yuckysocks Posted April 4, 2008 Share Posted April 4, 2008 Any help would be appreciated. Specifically, the <h4> tag doesn't contain anything when this is run. Thanks! <?php $id = intval($_GET['id']); echo "<div id=\"content\">"; echo "<h3 id=\"title\">Case Study Details</h3>"; $link = mysql_connect('localhost', 'name', 'pw') or die('Could not connect: ' . mysql_error()); mysql_select_db('case_studies') or die('Could not select database'); $query = "SELECT schoolname FROM casestudies WHERE id = $id"; $result = $schoolname; echo "<h4>$schoolname</h4>"; $query = "SELECT * FROM casestudies WHERE id = $id"; $result = mysql_query($query) or die('Query failed: ' . mysql_error()); $row = mysql_fetch_assoc($result); foreach ($row as $fld => $val) { echo "<p class=\"caseresult\"><b>$fld</b> : $val </p>"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/99580-why-wont-this-script-work-appropriately/ Share on other sites More sharing options...
kenrbnsn Posted April 4, 2008 Share Posted April 4, 2008 You need to do a query and a fetch before you can use the values. This <?php $query = "SELECT schoolname FROM casestudies WHERE id = $id"; $result = $schoolname; ?> should probably be <?php $query = "SELECT schoolname FROM casestudies WHERE id = $id"; $rs = mysql_query($query) or die("Problem with the query: $query<br>" . mysql_error()); $rw = mysql_fetch_assoc($rs); $result = $rw['schoolname']; ?> Also, why don't you just use your second query first, so you don't have to issue the same query twice? Ken Quote Link to comment https://forums.phpfreaks.com/topic/99580-why-wont-this-script-work-appropriately/#findComment-509426 Share on other sites More sharing options...
yuckysocks Posted April 4, 2008 Author Share Posted April 4, 2008 Well, <looking at toes> the real answer is I don't know enough about PHP to do otherwise. This is an amalgam of copied and pasted code with my own database names thrown in. Thanks for the tips Quote Link to comment https://forums.phpfreaks.com/topic/99580-why-wont-this-script-work-appropriately/#findComment-509428 Share on other sites More sharing options...
yuckysocks Posted April 4, 2008 Author Share Posted April 4, 2008 Well, <looking at toes> the real answer is I don't know enough about PHP to do otherwise. This is an amalgam of copied and pasted code with my own database names thrown in. Thanks for the tips I guess my -REAL- answer is that I don't know how to pull just the piece of data I want out of the array that's produce by the first query. Back to the books I suppose. Quote Link to comment https://forums.phpfreaks.com/topic/99580-why-wont-this-script-work-appropriately/#findComment-509448 Share on other sites More sharing options...
kenrbnsn Posted April 4, 2008 Share Posted April 4, 2008 Try: <?php $id = intval($_GET['id']); echo '<div id="content">'; echo '<h3 id="title">Case Study Details</h3>'; $link = mysql_connect('localhost', 'name', 'pw') or die('Could not connect: ' . mysql_error()); mysql_select_db('case_studies') or die('Could not select database'); $query = "SELECT * FROM casestudies WHERE id = $id"; $result = mysql_query($query) or die('Query failed: ' . mysql_error()); $row = mysql_fetch_assoc($result); echo "<h4>{$row['schoolname']}</h4>"; foreach ($row as $fld => $val) { echo '<p class="caseresult"><b>' . $fld . '</b> : ' . $val . '</p>'; } ?> Ken Quote Link to comment https://forums.phpfreaks.com/topic/99580-why-wont-this-script-work-appropriately/#findComment-509455 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.