Forum Moderators: coopster
$result = mysql_query("SELECT * FROM Items");
while ($row = mysql_fetch_array($result)) {
echo "<tr><td>">".$row{'item_name'}."</td><td>".$row{'item_pages'}."</td><td>".$row{'item_desc'}."</td></tr>";
}
You can see the three columns I return from the table are 'item_name', 'item_pages', and 'item_desc'. All works fine and it makes a table with as many rows as there are results.
The problem starts now I've attempted to add clickability to my results for "item_name" so I can simply click on any 'item_name' result and retrieve that file; 'item_name' stores complete file names in the database. The first, intermediate step was to see if I could insert a dead-end hyperlink, with 'item_name, and keep the formatting within the table:
while ($row = mysql_fetch_array($result)) {
echo "<tr><td><a href=\"#\">".$row{'item_name'}."</a></td><td>".$row{'item_pages'}."</td><td>".$row{'item_desc'}."</td></tr>";
}
while ($row = mysql_fetch_array($result)) {
echo "<tr><td><a href=\".$row{'item_name'}.\">".$row{'item_name'}."</a></td><td>".$row{'item_pages'}."</td><td>".$row{'item_desc'}."</td></tr>";
} Previously (didn't create hyperlink):
echo "<tr><td><a href=\".$row{item_name}.\">".$row{'item_name'}."</a></td> Currently (creates proper hyperlink):
echo "<tr><td><a href=\"$row[item_name]\">".$row{'item_name'}."</a></td> That is, in HTML, columns within an array appear to require square brackets around their name (eg.[item_name]) to display the field's value, whereas in PHP, we seem to need braces and apostrophes around the column's name (eg. {'item_name'}). Thanks for the 'view source'pointer which allowed me to get there.
On a side note, if anyone here feels strongly that an excellent database engineering program exists in either a US or Euro university, I would love to hear about it. Thanks.
in your case $row is an array, as returned from mysql_fetch_array or like function
you can access the parts of this array as such
$row['column_name']
though really that isn't 100% true as what is returned from a query is not always a column name