Announcement

Collapse
No announcement yet.

Need help on script that displays multiple MySQL rows

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • krs-one
    replied
    you have this:
    PHP Code:
    for ($counter=1$counter<=$last$counter++) { 
    Change it to this:
    PHP Code:
    for ($counter=0$counter<$last$counter++) { 
    Since the number of rows is storred in an array (I believe), it starts at zero, not one.

    Hope this helps.
    -Vic

    Leave a comment:


  • B&WDude
    started a topic Need help on script that displays multiple MySQL rows

    Need help on script that displays multiple MySQL rows

    I've started creating a script that accesses the database and gets the information, but I need help getting it to display the right results. It displays the right number, just not the right data. Here is what I have so far (using a for loop):

    PHP Code:
    // define server variables
    $DBServer "server";
    $DBUser "user";
    $DBPass "pass";
    $DBName "database";
    $DBTable "songs";

    // connect to MySQL database
    mysql_connect($DBServer,$DBUser,$DBPass) or die("Unable to connect to database.");
    mysql_select_db("$DBName") or die("Unable to access the song list.");

    // get number of songs for while loop
    $sqlquery "SELECT songid FROM songs WHERE songid > 0 ORDER by songid DESC LIMIT 0,10";
    $result mysql_query($sqlquery);
    $number mysql_numrows($result);
    $lastquery "SELECT songid FROM songs WHERE songid = $number";
    $lastresult mysql_query($lastquery);
    $last mysql_result($lastresult"songid");

    for (
    $counter=1$counter<=$last$counter++) {

    // get song numbers
    $songquery "SELECT songid FROM $DBTable ORDER by songid LIMIT 0,10";
    $songresult mysql_query($songquery);
    $song mysql_result($songresult,"songid");


    // get song titles
    $titlequery "SELECT title FROM $DBTable ORDER by songid LIMIT 0,10";
    $titleresult mysql_query($titlequery);
    $title mysql_result($titleresult,"title");

    // get download link
    $dloadquery "SELECT dloadlink FROM $DBTable ORDER by songid LIMIT 0,10";
    $dloadresult mysql_query($dloadquery);
    $dload mysql_result($dloadresult,"dloadlink");

    // print the song info out
    print "<B>$song. <a href=$dload>$title</a>";

    The script currently gives me the same row of data twice (2 rows in the database total). I want it to display one of each row.

    What shoul I do?
    Thanks in advance!
    Last edited by B&WDude; Sun 27 May '01, 8:07pm.
widgetinstance 262 (Related Topics) skipped due to lack of content & hide_module_if_empty option.
Working...
X