minus84 Posted September 9, 2010 Share Posted September 9, 2010 i dont knw why its keep telling me Notice: Undefined variable: lowdownDisplay in C:\wamp\www\bullshit.php on line 112 some1 please tell me wot i can do to fix this $sql = mysql_query("SELECT id, mem_id, the_lowdown, post_time FROM lowdown_db ORDER BY post_time DESC LIMI 20"); //$lowdownDisplayList = ''; while ($row = mysql_fetch_array($sql)) { //$lowdownDisplay = '<table width="0%" border="0" align="center" cellpadding="5"> //<tr>'; $lowdownid = $row["id"]; $uid = $row["mem_id"]; $the_lowdown = $row["the_lowdown"]; $the_date = $row["post_time"]; $the_date = strftime("%b %d, %Y", strtotime($post_time)); ///// inner SQL QUERY $sql_mem_data = mysql_query("SELECT id, firstname, lastname FROM mymembers WHERE id='$uid' LIMIT 1"); $lowdownDisplayList.= '<td><div style="height:80px; overflow:hidden;" > ' .$user_pic. ' </div><a href="profile.php?id=' .$id. '"><br>'.$firstname.' '.$lastname.'</a></td> '; //$lowdownDisplayList = ''<td><div style="height:80px; overflow:hidden;" > ' .$user_pic. ' </div><a href="profile.php?id=' .$id. '"><br>'.$firstname.' '.$lastname.'</a></td> '; while ($row = mysql_fetch_array($sql_mem_data)){ $uid = $row["id"]; $ufirstname = $row["firstname"]; $ufirstname = $row["lastname"]; $ufirstname = substr($ufirstname,0,10); ///////display lowdown pic////////// $ucheck_pic = "memberFiles/$uid/image01.jpg"; $udefault_pic = "memberFiles/0/image01.jpg"; if (file_exists($ucheck_pic)) { $lowdown_pic = "<img src=\"$check_pic\" width=\"40px\" />"; // forces picture to be 100px wide and no more } else { $lowdown_pic = "<img src=\"$default_pic\" width=\"40px\" />"; // forces default picture to be 100px wide and no more } $lowdownDisplayList.= ' <table width="95%" align="center" cellpadding="4" bgcolor="#ffffff"> <tr> <td width="7%" height="161" bgcolor="#996600"><a href="profile.php?id=' .$id .'">' .$lowdown_pic . '</a><br/> </td> <td width="93%" bgcolor="#CCCCCC" ><a href="profile.php?id=' .$id .'">' .$ufirstname . ' ' .$ulastname . ' </a> • <span style="font-size:10px;"> ' .$post_time . ' </span><br/> ' .$the_lowdown. ' </td> </table>'; } } ?> [code/] Quote Link to comment https://forums.phpfreaks.com/topic/212928-undefine-variable-ive-tried-everything/ Share on other sites More sharing options...
pornophobic Posted September 9, 2010 Share Posted September 9, 2010 before you try $lowdownDisplayList.= Put in something like this: $lowdownDisplayList = ''; That'll fix your problem. Quote Link to comment https://forums.phpfreaks.com/topic/212928-undefine-variable-ive-tried-everything/#findComment-1109017 Share on other sites More sharing options...
fortnox007 Posted September 9, 2010 Share Posted September 9, 2010 $lowdownDisplayList.= ' <----- is bad Do you have a program that shows line numbers? I use NetBeans, easier to detect errors Quote Link to comment https://forums.phpfreaks.com/topic/212928-undefine-variable-ive-tried-everything/#findComment-1109030 Share on other sites More sharing options...
pornophobic Posted September 9, 2010 Share Posted September 9, 2010 $lowdownDisplayList.= ' <----- is bad Why? Quote Link to comment https://forums.phpfreaks.com/topic/212928-undefine-variable-ive-tried-everything/#findComment-1109037 Share on other sites More sharing options...
objnoob Posted September 9, 2010 Share Posted September 9, 2010 To avoid these notices, make sure to define variables before trying to to use them. Remember, using a self acting concatenation or operand such as .= or += will rely on the said variable's value prior to reassignment. So if said variables value is unset, an undefined variable notice is thrown. .= <-- is not bad. Just declare the variable first using $myVar = null; Quote Link to comment https://forums.phpfreaks.com/topic/212928-undefine-variable-ive-tried-everything/#findComment-1109050 Share on other sites More sharing options...
minus84 Posted September 9, 2010 Author Share Posted September 9, 2010 thnx i got that problem solved but the table styll wont loop to take the information out ot the database. i dont knw why im using the same sciprt on another loop and it works fine <? $sql_lowdown = mysql_query("SELECT id, mem_id, the_lowdown, post_time FROM lowdown_db WhHERE mem_id='$id' ORDER BY post_time DESC LIMI 20"); while($row = mysql_fetch_array($sql_lowdown)) { $lowid = $row["id"]; $uid = $row["mem_id"]; $the_lowdown = $row["the_lowdown"]; $the_date = $row["post_time"]; $the_date = strftime("%b %d, %Y", strtotime($post_time)); $LowdownDisplayList.= ' <table width="95%" align="center" cellpadding="4" bgcolor="#ffffff"> <tr> <td width="7%" height="161" bgcolor="#996600"><a href="profile.php?id=' .$id .'">' .$lowdown_pic . '</a><br/> </td> <td width="93%" bgcolor="#CCCCCC" ><a href="profile.php?id=' .$id .'">' .$firstname . ' ' .$lastname . ' </a> • <span style="font-size:10px;"> ' .$post_time . ' </span><br/> ' . $the_lowdown . ' </td> </table>'; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/212928-undefine-variable-ive-tried-everything/#findComment-1109156 Share on other sites More sharing options...
mikosiko Posted September 9, 2010 Share Posted September 9, 2010 in the code that you were showing (you just changed the code in your post) the variable $id is undefined, that will more likely cause that your query $sql_lowdown = mysql_query("SELECT id, mem_id, the_lowdown, post_time FROM lowdown_db WhHERE mem_id='$id' ORDER BY post_time DESC LIMI 20"); will either fail or not return any value. you must validate that your $id variable effectively has some value and then rewrite that code in this alternative way: $sql_lowdown = mysql_query("SELECT id, mem_id, the_lowdown, post_time FROM lowdown_db WhHERE mem_id='$id' ORDER BY post_time DESC LIMI 20") or die("Query Error: " . mysql_error()); if (mysql_num_rows($sql_lowdown) > 0) { // The query returned values... therefore here you canb continue the rest of your code } else { echo "..No records found.."; }; Quote Link to comment https://forums.phpfreaks.com/topic/212928-undefine-variable-ive-tried-everything/#findComment-1109159 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.