2

I'm having a hard time figuring out how to get my table to display as a web page.

Everything else is working fine. I've been able to use a form to write records TO the table, but I'm simply unable to display the table.

Here's my code:

$host = "***";
$userName = "***";
$passWord = "***";
$db = "doctorWho";

mysql_connect($host,$userName,$passWord);
mysql_select_db($db) or die( "Unable to access database");
$query = "SELECT * FROM patients";

$result = mysql_query($query);

echo "<table border='1'>
    <tr>
    <th>Last Name</th>
    <th>First Name</th>
    <th>Address</th>
    <th>Age</th>
    <th>Sex</th>
    <th>Marital Status</th>
    <th>Medication</th>
    <th>Date Rx'd</th>
    <th>Quantity</th>
    </tr>";

while($row = mysqli_fetch_array($result))
  {
  echo "<tr>";
  echo "<td>" . $row['lastName'] . "</td>";
  echo "<td>" . $row['firstName'] . "</td>";
  echo "<td>" . $row['address'] . "</td>";
  echo "<td>" . $row['age'] . "</td>";
  echo "<td>" . $row['sex'] . "</td>";
  echo "<td>" . $row['maritalStatus'] . "</td>";
  echo "<td>" . $row['medication'] . "</td>";
  echo "<td>" . $row['medsWhen'] . "</td>";
  echo "<td>" . $row['medsQuant'] . "</td>";
  echo "</tr>";

  }
echo "</table>";
3
  • 4
    Do not use mysql_*? It is deprecated. mysqlpi or PDO is the replacement and the newest beast in town. Commented Apr 1, 2013 at 7:36
  • and if you are using mysql than please dont do it .. reason is exactly what Mr. @Ed Heal is telling form more information check stackoverflow.com/questions/12859942/… Commented Apr 1, 2013 at 7:38
  • @NullPonyPointer - You make me sound like a horse Wilber Commented Apr 1, 2013 at 7:56

4 Answers 4

4

You want mysql_fetch_array(). Currently, you are mixing two different extensions. Each takes something different, relevant to the extension.

That aside, you should consider either PDO or MySQLi, which is where the wrong function you attempted to use is from. This article should help you decide which you could possibly use.

Sign up to request clarification or add additional context in comments.

8 Comments

@NullPonyPointer actually, I'm just a noob at this, slowly learning. Thanks for your help though!
@Pachi If this answer solved your problem, please consider accepting it by clicking the checkmark under the down arrow next to it, when it lets you.
@Pachi please noob doesnot mean we dont do debuting i am sure you are getting error and not trying(give enough attention ) to solve it also dont use @ operator to ignore error its always bad you must solve them
@Daedalus I'm working through this. Thank you very much for the information you've given me!
ignoring error is very bad .. and caused UN-identified defects and can rune whole project so its good to start solving and handling them properly
|
0

From php ref.

mixed mysqli_fetch_array ( mysqli_result $result [, int $resulttype = MYSQLI_BOTH ] )

mysqli_fetch_array need to mysqli_result, but you are using mysql_query, you should try mysql_fetch_array

Comments

0
// I think your connection should look like this
$conn = mysql_connect($host,$userName,$passWord);
mysql_select_db($conn,$db) or die( "Unable to access database");

// another is your using mysql as connection so you can use mysqli functions on that rofl.
//Instead use mysql functions
mysql_fetch_array();

note: Another one is instead of using @ sign to handle error. Its much more best practice to use.. ini_set() or configuring php.ini in handling displaying of errors.

1 Comment

please don't use @ its bad practice to use this
0

Just change:-

while($row = mysqli_fetch_array($result))

to

while($row = mysql_fetch_array($result))

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.