techker Posted April 1, 2008 Share Posted April 1, 2008 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.... Quote Link to comment Share on other sites More sharing options...
techker Posted April 1, 2008 Author Share Posted April 1, 2008 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 Quote Link to comment Share on other sites More sharing options...
aschk Posted April 2, 2008 Share Posted April 2, 2008 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. Quote Link to comment Share on other sites More sharing options...
techker Posted April 2, 2008 Author Share Posted April 2, 2008 ya could be so..but i wan't to do that cause he has lots of products and i wan't to show it. Quote Link to comment Share on other sites More sharing options...
quiettech Posted April 2, 2008 Share Posted April 2, 2008 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 Quote Link to comment Share on other sites More sharing options...
techker Posted April 2, 2008 Author Share Posted April 2, 2008 i googled aschk advice and came up with nothing?what is that? and for the select it is good but i get the same image in the 4 boxes? Quote Link to comment Share on other sites More sharing options...
quiettech Posted April 2, 2008 Share Posted April 2, 2008 Please provide us with more detailed information. What is that you really want to do. And a summary of the relevant DDL for this particular issue. Quote Link to comment Share on other sites More sharing options...
techker Posted April 2, 2008 Author Share Posted April 2, 2008 ok.i have a page for my friend that contains an iframe that i want to extract for the database some images and text uder it.just to show some products. so i want on the top line 4 boxes with diffrent images in each. Quote Link to comment Share on other sites More sharing options...
quiettech Posted April 2, 2008 Share Posted April 2, 2008 How did you use my select statement? Show me. And show me the table DDL. Quote Link to comment Share on other sites More sharing options...
techker Posted April 2, 2008 Author Share Posted April 2, 2008 <?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> Quote Link to comment Share on other sites More sharing options...
quiettech Posted April 2, 2008 Share Posted April 2, 2008 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. Quote Link to comment Share on other sites More sharing options...
techker Posted April 2, 2008 Author Share Posted April 2, 2008 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? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.