SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Enthusiast
    Join Date
    Aug 2004
    Location
    FL
    Posts
    72
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Having trouble with product display script.

    I've been working on a review site for a while now, i just finished writing the review submission form and now im writing the review display part (products.php) but im having some issues with it. Here's my code:

    Code:
    <?php
    $databaseserver = "localhost";
    $databasename = "raemagc_reviews"; //the name of your database on the mysql server
    $databaseuser = "raemagc_admin"; //the name of the database-user
    $databasepass = "pass"; // the password to database
    $db = mysql_connect($databaseserver, $databaseuser, $databasepass);
    mysql_select_db($databasename,$db);
    if(!mysql_select_db("raemagc_reviews", $db))   {
                                     die("DATABASE SELECTION FAILED");
                                     }
    function ratings ($id){
          $query="SELECT * FROM `gratings` WHERE id = `$id`";
          $res = mysql_query($query);
          if(!$res){
          die ("Couldn't execute select query?!  Something's gone horribly 
    wrong.");
          }
          $numrows = mysql_num_rows($res);
          $feature = 0;
          $sound = 0;
          $action = 0;
          $realiability = 0;
          $suppert =0;
          $overall = 0;
          while($arr = mysql_fetch_array($res, MYSQL_ASSOC)) {
          $feature .= $arr[featurerating];
          $sound .= $arr[soundrating];
          $action .= $arr[actionrating];
          $reliability .= $arr[reliabilityrating];
          $support .= $arr[supportrating];
          $overall .= $arr[overallrating];
          }
          $e_feature = $feature / $numrows;
          $e_sound = $sound / $numrows;
          $e_action = $action / $numrows;
          $e_reliability = $reliability / $numrows;
          $e_support = $support / $numrows;
          $e_overall = $overall / $numrows;
    
          echo "
                                                                     <table 
    width=\"281\" align=\"center\" cellpadding=\"0\" cellspacing=\"0\">
                                                                      <tr 
    class=\"font_grey\">
                                                                        <td 
    width=\"140\"><strong>Features </strong></td>
                                                                        <td 
    width=\"136\">$e_feature<</td>
                                                                      </tr>
                                                                      <tr 
    class=\"font_grey\">
                                                                        
    <td><strong>Sound </strong></td>
                                                                        
    <td>Sound:       $e_sound </td>
                                                                      </tr>
                                                                      <tr 
    class=\"font_grey\">
                                                                        
    <td><strong>Action, Fit, &amp; Finish </strong></td>
                                                                        
    <td>Action:      $e_action </td>
                                                                      </tr>
                                                                      <tr 
    class=\"font_grey\">
                                                                        
    <td><strong>Reliability/Durability </strong></td>
                                                                        
    <td>Reliability: $e_reliability </td>
                                                                      </tr>
                                                                      <tr 
    class=\"font_grey\">
                                                                        
    <td><strong>Customer Support </strong></td>
                                                                        
    <td>Support:     $e_support</td>
                                                                      </tr>
                                                                      <tr 
    class=\"font_grey\">
                                                                        
    <td><strong>Overall Rating </strong></td>
                                                                        
    <td>Overall:     $e_overall</td>
                                                                      </tr>
                                                                    </table>
          ";
    }
         if (isset($manufacturer)){
                            if (isset($model)){
                                      if (isset($review)){
                                                $query="SELECT * FROM `greviews` 
    WHERE id = `$_GET[review]`";
                                                $res = mysql_query($query);
                                                if(!$res)
                                                die ("Couldn't execute select 
    query?!  Something's gone horribly wrong.");
                                                $numrows = mysql_num_rows($res);
                                                while($arr = 
    mysql_fetch_array($res, MYSQL_ASSOC)) {
                                                echo "
                                                         <table><tr>
                                                         ";
                                                                      
    ratings($arr[$_GET[review]]);
                                                                      echo "
                                                                    <p 
    align=\"center\"><strong>Submit a review for this product!</strong></p>      
                     </td>
                                                                </tr>
                                                                <tr>
                                                                  <td 
    align=\"left\" valign=\"top\" class=\"font_grey\"><p>&nbsp;</p>
                                                                    <p>Price 
    Paid: $arr[pricepaid]<br>
                                                                      <br>
                                                                      Purchased 
    from: $arr[purchasedfrom]<br>
                                                                      <br>
                                                                      
    Features:$arr[featurerating]<br>
                                                                      
    $arr[features]                        <br>
                                                                      <br>
                                                                      
    Sound:$arr[soundrating]<br>
                                                                      
    $arr[sound]                        <br>
                                                                      <br>
                                                                      Action, 
    Fit, &amp; Finish:$arr[actionrating]<br>
                                                                      
    $arr[action]                        <br>
                                                                      <br>
                                                                      
    Reliability/Durability: $arr[reliabilityrating]<br>
                                                                      
    $arr[reliability]                        <br>
                                                                      <br>
    
                                                                      Customer 
    Support: $arr[supportrating]<br>
                                                                      
    $arr[support]<br>
                                                                      <br>
                                                                      Overall 
    Rating: $arr[overallrating]<br>
                                                                      
    $arr[overall]                        <br>
                                                                      <br>
                                                                      Submitted 
    by:$arr[show] (if &quot;yes&quot;show)post: (if no show)post: Anonymous<br>
                                                                      
    Name:$arr[name]<br>
                                                                      
    E-mail:$arr[email]<br>
                                                                    </p>         
                    <p>&nbsp;</p></td>
                                                                </tr>
                                                            </table>
                                                ";
                                                }
    											}
                                      else {
                                                $query="SELECT * FROM `greviews` 
    WHERE parent_id = `$_GET[model]`";
                                                $res = mysql_query($query);
                                                if(!$res)
                                                die ("Couldn't execute select 
    query?!  Something's gone horribly wrong.");
                                                $numrows = mysql_num_rows($res);
                                                while($arr = 
    mysql_fetch_array($res, MYSQL_ASSOC)) {
                                                echo "                       
                                                Review: <a 
    href=?manufacturer=$_GET[manufacturers]&models=$_GET[models]&review=$arr[id]>Review</a><br>
                                                ";
                                                }
                                      }
                          }  else {
    $maker = $_GET[manufacturer];
                                                 $query="SELECT * FROM `gmodels` WHERE parent_id=$maker";
                                                 $res = mysql_query($query);
                                                 if(!$res)
                                                 die ("Couldn't execute select query?!  Something's gone horribly wrong.");
                                                 $numrows = mysql_num_rows($res);
                                                 while($arr = mysql_fetch_array($res, MYSQL_ASSOC)) { 
     $parent = $arr["parent_id"];
     $models = $arr["models"];                                             
     echo " 
                                                  Model: <a href=?manufacturer=$parent  
                                                  &models=$models>$models</a><br>    
                                                  ";                                           }
                            }
         }
         else {
              $query="SELECT * FROM `gmanufacturers`ORDER BY manufacturers";
              $res = mysql_query($query);
              if(!$res)
              die ("Couldn't execute select query?!  Something's gone horribly 
    wrong.");
              $numrows = mysql_num_rows($res);
              while($arr = mysql_fetch_array($res, MYSQL_ASSOC)) {
              echo "
              Manufacturer: <a 
    href=?manufacturer=$arr[id]>$arr[manufacturers]</a><br>
              ";
              }
         }
    ?>
    This is the page of the script: http://raemag.com/products.php

    The manufacturers and models show perfectly, but i cant get the link to the reviews to work, which is this part:

    Code:
    $maker = $_GET[manufacturer];
                                                 $query="SELECT * FROM `gmodels` WHERE parent_id=$maker";
                                                 $res = mysql_query($query);
                                                 if(!$res)
                                                 die ("Couldn't execute select query?!  Something's gone horribly wrong.");
                                                 $numrows = mysql_num_rows($res);
                                                 while($arr = mysql_fetch_array($res, MYSQL_ASSOC)) { 
     $parent = $arr["parent_id"];
     $models = $arr["models"];                                             
     echo " 
                                                  Model: <a href=?manufacturer=$parent  
                                                  &models=$models>$models</a><br>    
                                                  ";                                           }
    Any help is much appreciated!

  2. #2
    SitePoint Addict trigger's Avatar
    Join Date
    Jun 2003
    Location
    Eagan
    Posts
    342
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    try a little concatenation and slashes to escape special characters.

    echo "Model <a href=\""?manufacturer=".$parent.
    "&models=".$models.\">$models</a><br>";
    Not another drugstore, not another town
    Tired of the overdrop, I had to put it down
    You know I was the man when I put the Crown down
    Then rolled around the Chemicals to pave the New Sound

  3. #3
    SitePoint Enthusiast
    Join Date
    Aug 2004
    Location
    FL
    Posts
    72
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by trigger
    try a little concatenation and slashes to escape special characters.

    echo "Model <a href=\""?manufacturer=".$parent.
    "&models=".$models.\">$models</a><br>";
    I tried using that code, but i got a parse error:

    Parse error: parse error, unexpected '=' in /home/raemagc/public_html/products.php on line 189

    (line 189 is echo "Model <a href=\""?manufacturer=".$parent.)

    Whats that about?

  4. #4
    SitePoint Member jdk's Avatar
    Join Date
    Aug 2000
    Location
    New Jersey, USA
    Posts
    22
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    $original_link 'http://link_to_your_script/script.php?manufacturer=##MANUFACTURER##&models=##MODELS##';

    $actual_link $original_link;
    $actual_link str_replace('##MANUFACTURER##',urlencode($manufacturer),$actual_link);
    $actual_link str_replace('##MODELS##',urlencode($models),$actual_link); 
    ________________________________
    d. k. jariwala
    I blog at http://jdk.phpkid.org

  5. #5
    SitePoint Addict trigger's Avatar
    Join Date
    Jun 2003
    Location
    Eagan
    Posts
    342
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    you can also cheat a bit, and run in and out of php
    PHP Code:
    ?>Model <a href="
    <?php echo "partDetail.php?manufacturer=".urlencode($parent)."&models=".urlencode($models);?>"><?php echo $models;?></a></td>
    Not another drugstore, not another town
    Tired of the overdrop, I had to put it down
    You know I was the man when I put the Crown down
    Then rolled around the Chemicals to pave the New Sound

  6. #6
    SitePoint Member jdk's Avatar
    Join Date
    Aug 2000
    Location
    New Jersey, USA
    Posts
    22
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Though my code is 4 lines, I prefer it because it is READABLE and MAINTAINABLE.

    JD
    ________________________________
    d. k. jariwala
    I blog at http://jdk.phpkid.org


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •