Author | Message | Time |
---|---|---|
j0k3r | I've written my page so it can get the first row from MySQL, now how would I go about getting the second row? | February 12, 2004, 3:06 AM |
Ersan | [code]global $myrow; @mysql_query(" SELECT * from {tablename} "); $myrow = mysql_fetch_array($result); if($myrow != NULL) { extract($myrow); echo(" $data1, $data2, $data3 "); }[/code] | February 12, 2004, 3:22 AM |
j0k3r | That didn't help much, maybe posting some of my code would've been good... [code]$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'];[/code] 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. | February 12, 2004, 2:51 PM |
St0rm.iD | Oh my god, that's disgusting. [code] $result = mysql_query("SELECT * FROM `table1`"); while ($row = mysql_fetch_array($result)) { echo "[".$row['date']."] \"".$row['title']."\" ".$row['name']."<br /><br />"; echo $row['message']; } [/code] | February 12, 2004, 10:05 PM |
j0k3r | [quote author=St0rm.iD link=board=22;threadid=5242;start=0#msg43881 date=1076623535] Oh my god, that's disgusting. [/quote] 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++. | February 12, 2004, 11:05 PM |
St0rm.iD | sure anytime | February 14, 2004, 12:45 AM |
j0k3r | [quote author=St0rm.iD link=board=22;threadid=5242;start=0#msg43881 date=1076623535] [code] while ($row = mysql_fetch_array($result)) { [/code] [/quote] While we're on it, explain how that line works please? | February 14, 2004, 1:50 AM |
St0rm.iD | 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. | February 14, 2004, 3:14 PM |
j0k3r | 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] | February 14, 2004, 6:28 PM |
St0rm.iD | $result is just a pointer. It just references the results of a query, its nothing special. | February 14, 2004, 9:38 PM |
CrAzY | [quote author=j0k3r link=board=22;threadid=5242;start=0#msg44155 date=1076723442] [quote author=St0rm.iD link=board=22;threadid=5242;start=0#msg43881 date=1076623535] [code] while ($row = mysql_fetch_array($result)) { [/code] [/quote] While we're on it, explain how that line works please? [/quote] He's Right... | February 16, 2004, 1:38 PM |
j0k3r | [quote author=CrAzY link=board=22;threadid=5242;start=0#msg44566 date=1076938688] [quote author=j0k3r link=board=22;threadid=5242;start=0#msg44155 date=1076723442] [quote author=St0rm.iD link=board=22;threadid=5242;start=0#msg43881 date=1076623535] [code] while ($row = mysql_fetch_array($result)) { [/code] [/quote] While we're on it, explain how that line works please? [/quote] He's Right... [/quote] 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. | February 16, 2004, 11:48 PM |