jcdace Posted January 17, 2008 Share Posted January 17, 2008 hey all this is my first time here (kinda desperate for help), okay it might be reaaaly simple but i need aid fast! :-\ Basically i am creating a website selling website designs and i need to create a table displaying random themes (like template monster on the right hand side of the main page). i have all the table setup and the MYSQL and i can get it to display only the first theme on the list. i was wondering wether someone could help me with the PHP for showing random themes (Theme name, ID, Price etc.) in other words how can i display a different theme other than just the first one on the list? thanks for your time! Quote Link to comment https://forums.phpfreaks.com/topic/86555-solved-php-mysql-different-fields/ Share on other sites More sharing options...
Aureole Posted January 17, 2008 Share Posted January 17, 2008 This should set you a step in the right direction... but I don't know how you have everything set-up in your Database and on your Website... EDIT: I didn't read that you wanted RANDOM themes... nevermind. Quote Link to comment https://forums.phpfreaks.com/topic/86555-solved-php-mysql-different-fields/#findComment-442257 Share on other sites More sharing options...
jcdace Posted January 18, 2008 Author Share Posted January 18, 2008 ill have the code you were going to give out ... i realy want something to display a DIFFERENT Field. every single result is of the FIRST field in my database and i want to show FIELD 2 and 3 etc.. Quote Link to comment https://forums.phpfreaks.com/topic/86555-solved-php-mysql-different-fields/#findComment-442286 Share on other sites More sharing options...
Nhoj Posted January 18, 2008 Share Posted January 18, 2008 Post your MySQL query and maybe we can help ya out Quote Link to comment https://forums.phpfreaks.com/topic/86555-solved-php-mysql-different-fields/#findComment-442302 Share on other sites More sharing options...
jcdace Posted January 18, 2008 Author Share Posted January 18, 2008 ok i dont know what query you want me to send you but ill go through everythin ive done so far.... ok so firstly i created the table in dreamweaver to hold all the data. then I created the database for "templates" afer that i used dreamweaver to help add the following code at the top of the page: <?php if (!function_exists("GetSQLValueString")) { function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") { $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue; $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue); switch ($theType) { case "text": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "long": case "int": $theValue = ($theValue != "") ? intval($theValue) : "NULL"; break; case "double": $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL"; break; case "date": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "defined": $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue; break; } return $theValue; } } mysql_select_db($database_Epic_Creation, $Epic_Creation); $query_web_templates = "SELECT * FROM templates"; $web_templates = mysql_query($query_web_templates, $Epic_Creation) or die(mysql_error()); $row_web_templates = mysql_fetch_assoc($web_templates); $totalRows_web_templates = mysql_num_rows($web_templates); then after that i used the following code within the table (also found in dreamweaver) <table width="100%" border="0"> <tr> <td width="50%" height="251" align="center" valign="top"><table width="100%" border="0"> <tr> <td height="24"><div align="center" class="style3"> <?php echo $row_web_templates['name']; ?> </div></td> </tr> </table> <p><img src="img/newsbanner/blank.png" alt="" width="100" height="100" /></p> <table width="100%" height="56" border="0" bgcolor="#000000"> <tr> <td width="35%" height="16" class="style17">Author:</td> <td width="65%"><a href="profiles.php?username=<?php echo $row_web_templates['author']; ?>" class="style17"><?php echo $row_web_templates['author']; ?></a></td> </tr> <tr> <td height="16"><span class="style17">Price::</span></td> <td><span class="style17"><?php echo $row_web_templates['price']; ?></span></td> </tr> <tr> <td height="16"><span class="style17">Item#</span></td> <td><span class="style17"><?php echo $row_web_templates['ID']; ?></span></td> </tr> </table> <table width="100%" border="0" bgcolor="#8BAE13"> <tr> <td width="32%" height="16"><div align="center" class="style11"><span class="style18">View</span></div></td> <td width="35%"><div align="center" class="style11"><span class="style18">Cart</span></div></td> <td width="33%"><div align="center" class="style11"><span class="style18">Buy</span></div></td> </tr> </table></td> <td width="50%" align="center" valign="top"><table width="100%" border="0"><tr><td height="23"><div align="center"> <table width="100%" border="0"> <tr> <td height="17" valign="top"><div align="center"><span class="style3"><?php echo $row_web_templates['name']; ?></span></div></td> </tr> </table> <span class="style3"></span></div></td> </tr> </table> <p><img src="img/newsbanner/blank.png" alt="" width="100" height="100" /></p> <table width="100%" height="56" border="0" bgcolor="#000000"> <tr> <td width="35%" height="16" class="style17">Author:</td> <td width="65%"><a href="profiles.php?username=<?php echo $row_web_templates['author']; ?>" class="style17"><?php echo $row_web_templates['author']; ?></a></td> </tr> <tr> <td height="16"><span class="style17">Price::</span></td> <td><span class="style17"><?php echo $row_web_templates['price']; ?></span></td> </tr> <tr> <td height="16"><span class="style17">Item#</span></td> <td><span class="style17"><?php echo $row_web_templates['ID']; ?></span></td> </tr> </table> <table width="100%" border="0" bgcolor="#8BAE13"> <tr> <td width="32%" height="16"><div align="center" class="style11"><span class="style18">View</span></div></td> <td width="35%"><div align="center" class="style11"><span class="style18">Cart</span></div></td> <td width="33%"><div align="center" class="style11"><span class="style18">Buy</span></div></td> </tr> </table> </td> </tr> </table> Ok so ignore the HTML and focus on the PHP parts. when i use that code i get the following... Okay there are 4 of these on the page but they are ALL showing the same MYSQL field. and i want to know how can i get it to show different fields (E.G TEST THEME 2) and all its price ranges etc. Quote Link to comment https://forums.phpfreaks.com/topic/86555-solved-php-mysql-different-fields/#findComment-442697 Share on other sites More sharing options...
GingerRobot Posted January 18, 2008 Share Posted January 18, 2008 Eugh, Dreamweaver code and nested tables? What were you thinking? After a closer look, its even more confusing/messy than i thought! So ill just show you what you're missing, and ill leave you to sort out the layout. Basically, you need a loop - to loop through the returned results: <?php $query_web_templates = "SELECT * FROM templates"; $web_templates = mysql_query($query_web_templates, $Epic_Creation) or die(mysql_error()); $totalRows_web_templates = mysql_num_rows($web_templates); while($row_web_templates = mysql_fetch_assoc($web_templates)){ echo 'Name: '.$row_web_templates['name'].'<br />'; echo 'Author: '.$row_web_templates['author'].'<br />'; echo 'Price: '.$row_web_templates['price'].'<br />'; echo 'ID: '.$row_web_templates['ID'].'<br /><br />'; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/86555-solved-php-mysql-different-fields/#findComment-442703 Share on other sites More sharing options...
jcdace Posted January 18, 2008 Author Share Posted January 18, 2008 thnx alot GRobot XD it works but ive got a few problems still :'( its probably me having a "blonde" moment haha (im not even blonde) but the ECHO parts when i placd them at the top to test them one echo command produced all the fields. then when i attempted to place them in the tables i created it didnt even show up :S so i was wondering how can i place each result in a seperate table? P.S. thanks alot for your help so far Quote Link to comment https://forums.phpfreaks.com/topic/86555-solved-php-mysql-different-fields/#findComment-442715 Share on other sites More sharing options...
jcdace Posted January 18, 2008 Author Share Posted January 18, 2008 Sorry for the double post, but i cant find the "edit post" bit *sigh* anywho IVE FIXED IT its working awesomely thanks to ginger robot , thanks alot!! ill post a tutorial somewhere on this site aswell Quote Link to comment https://forums.phpfreaks.com/topic/86555-solved-php-mysql-different-fields/#findComment-442729 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.