Jump to content

[SOLVED] PHP & MYSQL - Different Fields?


Recommended Posts

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! ;D

 

Link to comment
https://forums.phpfreaks.com/topic/86555-solved-php-mysql-different-fields/
Share on other sites

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"

DATABASE.JPG

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...

 

TABLES.JPG

 

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.

Eugh, Dreamweaver code and nested tables? What were you thinking? :P

 

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 />';
}
?>

 

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  :P

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.