soycharliente Posted June 25, 2007 Share Posted June 25, 2007 My data is not being pulled from the db. I have no idea why. Can someone take a look at this code? This code populates a div in my page. The 'reason' field isn't coming through. <?php function getSpotlight() { dbconnect(); $query = "SELECT * FROM spotlight ORDER BY id DESC LIMIT 1"; $result = mysql_query($query) OR DIE ("Error: getSpotlight()."); if (mysql_num_rows($result) > 0) { while ($r = mysql_fetch_array($result)) { $member = $r["profileid"]; $reason = myEscape($r["reason"]); $pic = getProfileField("image", $member); $name = getName($member); $spot = "<img src=\"img/bros/$pic\" class=\"picB\" alt=\"Picture of $name\" /> <p><strong>$name</strong> $reason</p>\n"; return $spot; } } else { return "<p>No 'Alumni Spotlight' at this time.</p>\n"; } dbclose(); } ?> Here is the escape function. I took it from frost who posted it in response to something else a long time ago. Am I using it wrong or something? I'm using it in another query that is exactly the same as the one above except for a different table and it comes out fine. <?php function myEscape($string) { $new = get_magic_quotes_gpc() ? stripslashes($string) : $string; return mysql_real_escape_string($new); } ?> Only the image and the person's name are showing up in the div. The getProfileField() function is working fine so that can't be it. Link to comment https://forums.phpfreaks.com/topic/57171-solved-data-not-being-pulled-from-db/ Share on other sites More sharing options...
trq Posted June 26, 2007 Share Posted June 26, 2007 Why are you escaping data for display? You escape when inserting into a database.... theres not usually any other reasons to do so. Link to comment https://forums.phpfreaks.com/topic/57171-solved-data-not-being-pulled-from-db/#findComment-282482 Share on other sites More sharing options...
soycharliente Posted June 26, 2007 Author Share Posted June 26, 2007 Oh reeeallllllllllly? I guess I am using it wrong. That doesn't solve the problem though. Link to comment https://forums.phpfreaks.com/topic/57171-solved-data-not-being-pulled-from-db/#findComment-282486 Share on other sites More sharing options...
teng84 Posted June 26, 2007 Share Posted June 26, 2007 do this first print_r(mysql_fetch_array($result)); then if theres no result i think the problem will be on the connection function Link to comment https://forums.phpfreaks.com/topic/57171-solved-data-not-being-pulled-from-db/#findComment-282487 Share on other sites More sharing options...
trq Posted June 26, 2007 Share Posted June 26, 2007 Replace your while() with this... while ($r = mysql_fetch_array($result)) { print_r($r); } What does it produce? Link to comment https://forums.phpfreaks.com/topic/57171-solved-data-not-being-pulled-from-db/#findComment-282489 Share on other sites More sharing options...
soycharliente Posted June 26, 2007 Author Share Posted June 26, 2007 ROFL. I found the problem. I went to the db to double check that I even put in something for that field and I was referencing a field that didn't exist. Thanks for trying to help me. Link to comment https://forums.phpfreaks.com/topic/57171-solved-data-not-being-pulled-from-db/#findComment-282493 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.