Jump to content

multiple images


techker

Recommended Posts

hey guys i have a 2 quick question for you pros.

 

i have a site that i made a database that contains products.now i have every thing set up to view the products like a catalogue.

 

now on the site it self i made a product page in there i want to post the image and link it to the information page.that it's ok.

 

now the part im scratching my head is i wan't to post like 4 images but i need them different like a gallery in a square,how can i fetch only like 5 images in random order.

 

2 question.

 

i wan't to make a cool background to put the product image and description but how can i make that same bgw repeat with another on the same page?cause usually u just put the fetch code once and it shows all the product in your database....

Link to comment
Share on other sites

i tryed using the example in the sticky

 

$QQQ1 = mysql_query("SELECT
*
FROM
supps AS t1
INNER JOIN 
(
    SELECT
    ROUND(RAND() * (SELECT MAX(id) FROM supps)) AS id
) AS t2 
ON
t1.id >= t2.id 
ORDER BY
t1.id ASC 
LIMIT 1;  ");

 

works but all the same image?i need for diffrent

Link to comment
Share on other sites

I want to suggest something (which you DON'T have to adhere to), but I recommend selecting the SAME set of images each time, otherwise you risk alienating the user because you keep changing the images each time they come back to the page. Usability is very important in all web design aspects/decisions.

Link to comment
Share on other sites

I'm hoping all you are wanting to provide is a random selection of products in a sidebar or something... not a random selection of pictures for the same product. Otherwise, I strongly suggest go with aschk advice. You will be sorry otherwise.Some decisions on our part, that we find are good marketing choices, have an impact on the user experience. And that sometimes (read, almost always) backfires.

 

Anyways,

 

SELECT * FROM table_name WHERE condition ORDER BY RAND() LIMIT how_many

 

Is how you draw a random sample of some table on your database

Link to comment
Share on other sites

<?php // Connects to your Database
mysql_connect("localhost", "r", "t") or die(mysql_error());
mysql_select_db("gym") or die(mysql_error());

$QQQ1 = mysql_query("SELECT * FROM supps WHERE bin_data ORDER BY RAND() LIMIT 4 ");
if(!$QQQ1) die(mysql_error());
?>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
<table width="525" height="359" border="0" cellpadding="0" cellspacing="0">
  <tr><?php while ($info=mysql_fetch_array($QQQ1)) {?>
    <td valign="top"><table width="525" height="160" border="0" cellpadding="0" cellspacing="0">
      <tr>
        <td height="160"><div align="center"><?php echo '<a href="/admin/photo/'. $info['bin_data'] .'"target="_blank"><img src="/admin/photo/thumbs/'. $info['bin_data'] .'" border="0" alt="" /></a><br />'."\n";?></div></td>
        <td><div align="center"><?php echo '<a href="/admin/photo/'. $info['bin_data'] .'"target="_blank"><img src="/admin/photo/thumbs/'. $info['bin_data'] .'" border="0" alt="" /></a><br />'."\n";?></div></td>
        <td><div align="center"><?php echo '<a href="/admin/photo/'. $info['bin_data'] .'"target="_blank"><img src="/admin/photo/thumbs/'. $info['bin_data'] .'" border="0" alt="" /></a><br />'."\n";?></div></td>
        <td><div align="center"><?php echo '<a href="/admin/photo/'. $info['bin_data'] .'"target="_blank"><img src="/admin/photo/thumbs/'. $info['bin_data'] .'" border="0" alt="" /></a><br />'."\n";?></div></td>
      </tr>
    </table></td>
  </tr>
  <tr>
    <td valign="top"> </td>
  </tr>
  <? }?>
</table>
</body>
</html>

Link to comment
Share on other sites

WHERE bin_data always returns true (unless NULL). So you don't need it. I included it in case you had a conditional expression. You probably want instead:

 

SELECT bin_data FROM supps ORDER BY RAND() LIMIT 4

 

Also, I noticed if(!$QQQ1) die(mysql_error()). Don't ever, ever do that ;)

You are giving powerful information to some user who may be of the insidious type and wondering just exactly how to get into your database. Instead something like:

 

if(!$QQQ1) die('error parsing your request. Please contact us if this problem persists.')

 

The same goes for the connection and open database up there... although I'm partial to the die() function and prefer instead to use my own functions.

 

EDIT: Sorry, got sidetracked by the die() thing and didn't finish my post. Anyways, you are getting the same image because you are reading from the resultset 4 times before moving on to the next record. What you should do instead is echo the whole TD just once. The while loop will take charge and echo it 4 times. Once for every record.

Link to comment
Share on other sites

hm good point i was pasting the td to link the image to an info center..but you know what..screw it i will put a more button..lol

 

i get what your saying for the mysql.thanks for the heads up i very new at this..

 

 

edit:

 

by the way is there a way if i only use one td to make it on a horizontal line?cause now it echos in a vertical line?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.