lolclol Posted May 4, 2013 Share Posted May 4, 2013 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 https://forums.phpfreaks.com/topic/277627-going-well-till/ Share on other sites More sharing options...
Jessica Posted May 4, 2013 Share Posted May 4, 2013 $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 https://forums.phpfreaks.com/topic/277627-going-well-till/#findComment-1428221 Share on other sites More sharing options...
lolclol Posted May 5, 2013 Author Share Posted May 5, 2013 hi Jessica, just cant figure it out. Link to comment https://forums.phpfreaks.com/topic/277627-going-well-till/#findComment-1428310 Share on other sites More sharing options...
ignace Posted May 5, 2013 Share Posted May 5, 2013 $sql = "select * from mr_recipes WHERE id "; WHERE id Where id is what? You have to tell it what id you are looking for. Link to comment https://forums.phpfreaks.com/topic/277627-going-well-till/#findComment-1428314 Share on other sites More sharing options...
lolclol Posted May 5, 2013 Author Share Posted May 5, 2013 <?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 https://forums.phpfreaks.com/topic/277627-going-well-till/#findComment-1428317 Share on other sites More sharing options...
lolclol Posted May 5, 2013 Author Share Posted May 5, 2013 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 https://forums.phpfreaks.com/topic/277627-going-well-till/#findComment-1428323 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.