Jump to content

going well till


lolclol
Go to solution Solved by lolclol,

Recommended Posts

I have had a full day and half of coding and playing around to getting this working.

 

just a little stuck now.

http://cffoodtoday.com/recipe.php?id=6

 

I know the code below is a little messy. the code is showing all the database fields. and not just the ID the url is asking for,

<?php
  define("_VALID_PHP", true);
  require_once("init.php");
?>   <?php include("header.php");?>
	<div id="left-area" class="clearfix">
	        <!-- ============= CONTENT AREA STARTS HERE ============== -->

<?php $conn = mysql_connect("localhost", "user", "pass!");
mysql_select_db("_login1", $conn)
or die ('Database not found ' . mysql_error() );
$cust = $_GET["id"];
$sql = "select * from mr_recipes WHERE id ";
$rs = mysql_query($sql, $conn)
or die ('Database not found ' . mysql_error() );
$result = mysql_query("SELECT * FROM mr_recipes");

while($row = mysql_fetch_array($result)){
    // Prepare gamertag for url
    $id = strtolower($row['id']);
    //echo $gamertag.'<br />';
    $url = "recipe.php?id=".urlencode($id);
    $get_result = file_get_contents($url);
}
?>

<?php if (mysql_num_rows($rs)>0){ ?>

<?php while ($row = mysql_fetch_array($rs)) { ?>




						  <h1><?php echo $row["name"]?></h1>
              <span class="w-pet-border"></span>
              <div class="recipe-info">
                <h2><a href="#"></a></h2>
                <div class="recipe-tags"> <span class="type">Date: <?php echo $row["date"]?></span> <span class="cuisine">Recipe By: </span> <?php echo $row["username"]?></div>
                <p>.<br />
				Cook Time:<?php echo $row["cooktime"]?> ~ Prep Time<?php echo $row["perptime"]?>				
			    </p></div>
              <div class="post recipe-listing-item">
			    <div class="list-left">
			      <h3 class="blue">Ingredients </h3>

  <?php echo nl2br($row['ingredients']);?>
  

								     
							        </ul>

							      </div>

                                  <br />

                                  <h3 class="blue">Method</h3>
 <?php echo nl2br($row['instructions']);?>

						  </div><!-- end of recipe-listing-item div -->

						

								<div class="post recipe-listing-item"></div><!-- end of recipe-listing-item div -->

								

							<?php } ?>	      <?php }
else {?> <p>No recipes in  database.</p>
<?php } ?>    

</div><!-- end of left-area -->

				        <!-- LEFT AREA ENDS HERE -->

							

        <!-- end of content div -->

  <!-- ========== CONTENT AREA ENDS HERE ========== -->

                        

  </div><!-- end of container div -->

<div class="w-pet-border"></div>

<!-- ============= CONTAINER AREA ENDS HERE ============== -->

<?php include("footer.php");?>
Link to comment
Share on other sites


$sql = "select * from mr_recipes WHERE id ";
$rs = mysql_query($sql, $conn)
or die ('Database not found ' . mysql_error() );
$result = mysql_query("SELECT * FROM mr_recipes");

while($row = mysql_fetch_array($result)){
Exactly as you've told it to. Your first query (the one you should use) is missing the rest of the where clause btw.
Link to comment
Share on other sites

<?php $conn = mysql_connect("localhost", "user", "pass!");
mysql_select_db("_login1", $conn)
or die ('Database not found ' . mysql_error() );
$cust = $_GET["id"];
$sql = "select * from mr_recipes WHERE id='6'";
$rs = mysql_query($sql, $conn)
or die ('Database not found ' . mysql_error() );
?>

I understand that, that will show the id I want. but how do get it show it shows the id from the url?

Link to comment
Share on other sites

  • Solution

got it working

<?php $conn = mysql_connect("localhost", "user", "pass!");
mysql_select_db("_login1", $conn)
or die ('Database not found ' . mysql_error() );
$id=mysql_real_escape_string($_GET['id']);
$sql = "select * from mr_recipes WHERE id = $id";
$rs = mysql_query($sql, $conn)
or die ('Database not found ' . mysql_error() );
$result = mysql_query("SELECT * FROM mr_recipes");

while($row = mysql_fetch_array($result)){
    $id = strtolower($row['id']);
    $url = "recipe.php?id=".urlencode($id);
    $get_result = file_get_contents($url);
}
?>
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.