Outputing data from mysql;

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • darko
    New Member
    • Sep 2006
    • 10

    Outputing data from mysql;

    I'm pretty good at php and mysql, it's been sometime now that i was trying to find a way to output result, more then 1 at a time, so i came up with this function

    [PHP] function screenshots()
    {
    global $website_link;

    $name1 = $_GET['name'];
    $name= str_replace("-", " ", $name1);
    $query = @mysql_query("S ELECT * FROM `games` WHERE `name` = \"$name\" LIMIT 1");
    $id= @mysql_result($ query, 0, "id");
    $categorie= @mysql_result($ query, 0, "categorie" );
    $categorie1= str_replace(" ", "-", $categorie);
    $query = @mysql_query("S ELECT * FROM `screenshots` WHERE `gameid` = \"$id\"");
    $screenshots= @mysql_numrows( $query);
    echo "<table>
    <tr width=\"100%\"> <td>
    <a href=\"$website _link/games/$name1.html\">$ name</a>
    -
    <a href=\"$website _link/cheats/$name1.html\">C heats</a>
    -
    <a href=\"$website _link/screenshot/$name1.html\">S creenshot</a>
    -
    <a href=\"$website _link/downloads/$name1.html\">D ownloads</a>
    </td>
    </tr>
    <tr width=\"100%\">
    <td><a href=\"$website _link/categories/$categorie1.htm l\">$categori e</a> > <a href=\"$website _link/games/$name1.html\">$ name</a> > Screenshots</td></tr></table>";
    if(empty($scree nshots))
    {
    echo "No Screenshots Available";
    }
    $i = 0;
    echo"<table width=\"100%\"> ";
    for ($i=0; $i<$screenshots ; $i++)
    {
    $id = mysql_result($q uery, $i, "id");
    $gameid = mysql_result($q uery, $i, "gameid");
    $image= mysql_result($q uery, $i, "image");
    $comment = mysql_result($q uery, $i, "comment");
    $name = mysql_result($q uery, $i, "name");
    $b = 2;
    $c= $i/$b;

    if(!strrchr($c, "."))
    {
    echo"
    <tr align=\"center\ " width=\"50%\">
    <td>
    <a href=\"$image\" ><img src=\"$image\" width=\"200\" height=\"200\" /></a>
    <br />
    $name
    <br />
    $comment
    <br />
    --------------------------------------
    </td>";
    }
    else
    {
    echo" <td>
    <a href=\"$image\" ><img src=\"$image\" width=\"200\" height=\"200\" /></a>
    <br />
    $name
    <br />
    $comment
    <br />
    --------------------------------------
    </td>
    </tr>";
    };
    }
    echo"</table>";
    }
    [/PHP]

    this will output two images at a time, but what i want is for php to output 3 at a time, can anybody help me out
  • ronverdonk
    Recognized Expert Specialist
    • Jul 2006
    • 4259

    #2
    Exactly the same problem was handled and an answer given in thread http://www.thescripts.com/forum/thread545705.html . But to show you what your code looks like, the following:

    (P.S. The code is not tested so don't quarrel about a comma or so. And I made it a bit more readable and added an exit when no screenshots available)

    [php]
    function screenshots() {
    global $website_link;

    $name1 = $_GET['name'];
    $name= str_replace("-", " ", $name1);
    $query = @mysql_query("S ELECT * FROM `games` WHERE `name` = \"$name\" LIMIT 1");
    $id= @mysql_result($ query, 0, "id");
    $categorie= @mysql_result($ query, 0, "categorie" );
    $categorie1= str_replace(" ", "-", $categorie);
    $query = @mysql_query("S ELECT * FROM `screenshots` WHERE `gameid` = \"$id\"");
    $screenshots= @mysql_numrows( $query);

    echo "<table>
    <tr width=\"100%\">
    <td>
    <a href=\"$website _link/games/$name1.html\">$ name</a>-
    <a href=\"$website _link/cheats/$name1.html\">C heats</a>-
    <a href=\"$website _link/screenshot/$name1.html\">S creenshot</a>-
    <a href=\"$website _link/downloads/$name1.html\">D ownloads</a>
    </td>
    </tr>
    <tr width=\"100%\">
    <td>
    <a href=\"$website _link/categories/$categorie1.htm l\">$categori e</a> > <a href=\"$website _link/games/$name1.html\">$ name</a>Screenshots
    </td>
    </tr>
    </table>";
    if(empty($scree nshots)) {
    echo "No Screenshots Available";
    exit; ------->
    }

    $j = 0;
    echo"<table width=\"100%\"> ";
    for ($i=0; $i<$screenshots ; $i++) {
    $id = mysql_result($q uery, $i, "id");
    $gameid = mysql_result($q uery, $i, "gameid");
    $image= mysql_result($q uery, $i, "image");
    $comment = mysql_result($q uery, $i, "comment");
    $name = mysql_result($q uery, $i, "name");
    $j++;
    switch ($j) {
    case 1 : echo "<tr align=\"center\ " width=\"50%\">
    <td>
    <a href=\"$image\" ><img src=\"$image\" width=\"200\" height=\"200\" /></a>
    <br />$name<br />$comment<br />
    </td>";
    break;

    case 2 : echo "<td>
    <a href=\"$image\" ><img src=\"$image\" width=\"200\" height=\"200\" /></a>
    <br />$name<br />$comment<br />
    </td>";
    break;

    case 3 : echo "<td>
    <a href=\"$image\" ><img src=\"$image\" width=\"200\" height=\"200\" /></a>
    <br />$name<br />$comment<br />
    </td>
    </tr>";
    $j=0;
    break;
    }
    }
    if ($j < 3)
    echo "</tr>";
    echo "</table>";
    }
    [/php]

    Ronald :cool:

    Comment

    Working...