-
I'm new to mySQL, so I need some help retrieiving the stored data in the table.
Ok I've got 5 columns: id, url, title, and descrip.
How can I retrieve the information for the columns from each row?
So that it does something like this:
Code:
while (there are still some rows to get information from){
echo ("<a href='$url[0]'>$title[0]</a><br><small>$descrip[0]</small><br><br>");
}
I found out that getting information from mySQL dbs is harder the sending information to mySQL dbs. In my opinion, anyways.
Thanks for the help.
Suggestions for different methods and flames are welcome!
-
That's 4 columns, by the way. :)
Everything you need is explained in my article here. Meanwhile, here's your code:
Code:
$result = mysql_query("SELECT * FROM tableName") or die("Error: " . mysql_error());
while ($row = mysql_fetch_array($result)) {
$url = $row["url"];
$title = $row["title"];
$descrip = $row["descrip"];
echo ("<a href='$url'>$title</a><br><small>$descrip</small><br><br>");
}
[EDIT: fixed a small bug]
<Edited by kyank on 12-15-2000 at 11:19 PM>
-
Oh wow that's easy
Thanks
I tried that article, but I was sortof confused about what he ment at some parts. But now it's all clear. Thanks
-
He is me. If you have any lingering questions, ask away! :)
-
Warning: Supplied argument is not a valid MySQL result resource in /home2/webdev/public_html/links.php on line 32
Hmmm
PHP isn't liking :
Code:
while ($row = mysql_fetch_array($resultSet)) {
$id = $row["id"];
$url = $row["url"];
$title = $row["title"];
$descrip = $row["descrip"];
echo ("<a href='$url'>$title</a><br><small>$descrip<small><font color=gray>$id</font></small</small><br><br>");
}
My guess is the resultSet.. But then again I've never really used arrays much before..
-
Where is the code creating that $resultSet? It's the source of your problem. See my example above for the correct method.
-
We resolved this via email. Turns out the culprit was a typo in my code above, which I have since corrected.