I've written my page so it can get the first row from MySQL, now how would I go about getting the second row?
global $myrow;
@mysql_query(" SELECT * from {tablename} ");
$myrow = mysql_fetch_array($result);
if($myrow != NULL) {
extract($myrow);
echo(" $data1, $data2, $data3 ");
}
That didn't help much, maybe posting some of my code would've been good...
$selectdate = mysql_query("SELECT `date` FROM `table1`");
$selecttitle = mysql_query("SELECT `title` FROM `table1`");
$selectname = mysql_query("SELECT `name` FROM `table1`");
$selectmessage = mysql_query("SELECT `message` FROM `table1`");
$date = mysql_fetch_array($selectdate, MYSQL_ASSOC);
$title = mysql_fetch_array($selecttitle, MYSQL_ASSOC);
$name = mysql_fetch_array($selectname, MYSQL_ASSOC);
$message = mysql_fetch_array($selectmessage, MYSQL_ASSOC);
echo "[".$date['date']."] \"".$title['title']."\" ".$name['name']."<BR><BR>";
echo $message['message'];
It's really sloppy right now, I'll touch it up when I get home, but that just gets the first row, and right now there are 2, and eventually it will keep growing.
Oh my god, that's disgusting.
$result = mysql_query("SELECT * FROM `table1`");
while ($row = mysql_fetch_array($result)) {
echo "[".$row['date']."] \"".$row['title']."\" ".$row['name']."<br /><br />";
echo $row['message'];
}
Quote from: St0rm.iD on February 12, 2004, 04:05 PM
Oh my god, that's disgusting.
Lmao, first time I've heard someone call code disgusting. I threw it together in 5 minutes before going to bed, although I doubt I'd have been able to get it shrunk down that much, thanks++.
sure anytime
Quote from: St0rm.iD on February 12, 2004, 04:05 PM
while ($row = mysql_fetch_array($result)) {
While we're on it, explain how that line works please?
mysql_fetch_array returns FALSE when there are no more rows. The while loop checks $row as its loop condition. "Not null" corresponds to TRUE. When it becomes FALSE, the loop ends.
That wasn't what I meant :P
What values are stored in $result and how does mysql_fetch_array() work to get all the rows?
[edit]Happy 1000 to me ;D[/edit]
$result is just a pointer. It just references the results of a query, its nothing special.
Quote from: j0k3r on February 13, 2004, 07:50 PM
Quote from: St0rm.iD on February 12, 2004, 04:05 PM
while ($row = mysql_fetch_array($result)) {
While we're on it, explain how that line works please?
He's Right...
Quote from: CrAzY on February 16, 2004, 07:38 AM
Quote from: j0k3r on February 13, 2004, 07:50 PM
Quote from: St0rm.iD on February 12, 2004, 04:05 PM
while ($row = mysql_fetch_array($result)) {
While we're on it, explain how that line works please?
He's Right...
I never said he wasn't, I just didn't understand the line and wanted him to clarify so I don't just use someone else's code and be some leaching 'tard.