473,471 Members | 1,953 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Outputing data from mysql;

10 New Member
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("SELECT * 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("SELECT * 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\">Cheats</a>
-
<a href=\"$website_link/screenshot/$name1.html\">Screenshot</a>
-
<a href=\"$website_link/downloads/$name1.html\">Downloads</a>
</td>
</tr>
<tr width=\"100%\">
<td><a href=\"$website_link/categories/$categorie1.html\">$categorie</a> > <a href=\"$website_link/games/$name1.html\">$name</a> > Screenshots</td></tr></table>";
if(empty($screenshots))
{
echo "No Screenshots Available";
}
$i = 0;
echo"<table width=\"100%\">";
for ($i=0; $i<$screenshots; $i++)
{
$id = mysql_result($query, $i, "id");
$gameid = mysql_result($query, $i, "gameid");
$image= mysql_result($query, $i, "image");
$comment = mysql_result($query, $i, "comment");
$name = mysql_result($query, $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
Oct 23 '06 #1
1 1538
ronverdonk
4,258 Recognized Expert Specialist
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("SELECT * 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("SELECT * 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\">Cheats</a>-
<a href=\"$website_link/screenshot/$name1.html\">Screenshot</a>-
<a href=\"$website_link/downloads/$name1.html\">Downloads</a>
</td>
</tr>
<tr width=\"100%\">
<td>
<a href=\"$website_link/categories/$categorie1.html\">$categorie</a> > <a href=\"$website_link/games/$name1.html\">$name</a>Screenshots
</td>
</tr>
</table>";
if(empty($screenshots)) {
echo "No Screenshots Available";
exit; ------->
}

$j = 0;
echo"<table width=\"100%\">";
for ($i=0; $i<$screenshots; $i++) {
$id = mysql_result($query, $i, "id");
$gameid = mysql_result($query, $i, "gameid");
$image= mysql_result($query, $i, "image");
$comment = mysql_result($query, $i, "comment");
$name = mysql_result($query, $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:
Oct 23 '06 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: bissatch | last post by:
Hi, I have the following XML content in a file (main.xml): <?xml version="1.0" encoding="iso-8859-1"?> <menu> <option title="Home" href="home.php"> <option title="News" href="news.php">...
2
by: Antonio Ooi | last post by:
Hi, Probably due to my 'Language for non-Unicode Setting' in Regional Settings, my ASP page keeps outputing the date format as Chinese Simplified characters when issuing say, <%=Now()%>. In...
0
by: Donald Tyler | last post by:
Then the only way you can do it that I can think of is to write a PHP script to do basically what PHPMyAdmin is trying to do but without the LOCAL in there. However to do that you would need to...
12
by: Jerry Weinstein | last post by:
Hi, I know about stored procedures and that they can speed up data entry via the SQL 'insert ' statement. However, one drawback to this method is that using the stored procedure still requires...
4
by: George | last post by:
I am lost on how to do this. I have not worked with C much at all but can understand the basic properties of this language. Could someone please show me or explain to me how to write a function...
3
by: eieiohh | last post by:
MySQL 3.23.49 PHP 4.3.8 Apache 2.0.51 Hi All! Newbie.. I had a CRM Open Source application installed and running. Windows Xp crashed. I was able to copy the contents of the entire hard...
4
by: jdcrief | last post by:
Using Visual C++2005 Expression Edition Having trouble outputting the value referenced by the pointer and then outputing the address of the pointer for the char. Any ideas would be greatly...
8
by: Jon Slaughter | last post by:
can one "stream" image data to a browser? I created an image using gd and when I do imagepng I just get the binary data for the image written as text instead of the image itself. Now I'm...
26
by: cwby1966 | last post by:
I have VBA code that is to output 2 reports to snapshot format for emailing. When I add a cancel on the report if no data, the second report will not output even when there is data ...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.