Lamez Posted February 28, 2008 Share Posted February 28, 2008 I made a checkTable function, and its purpose is to find the row, and if the data is equal to 0 then show a drop down box, if not then show what is in another table, well it does neither, and I do not know why. Also this is one of my first functions, ever. here is the function: <?php $rnd = "rnd1_win"; $query = "SELECT * FROM `$rnd`"; $result = mysql_query($query); $win = mysql_fetch_array($result); $table = "rnd1_check"; $qu = "SELECT * FROM `$table`"; $re = mysql_query($qu); $ck = mysql_fetch_array($re); function checkTable($num, $a, $b){ if ($ch['r'.$num.''] === ("0")){ echo "<select>"; echo '<option value="emp"></option>'; echo '<option value="'.$a.'">'.$a.'</option>'; echo '<option value="'.$b.'">'.$b.'</option>'; echo '</select>'; }else{ echo $win[$a]; } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/93463-checktable-function/ Share on other sites More sharing options...
pocobueno1388 Posted February 28, 2008 Share Posted February 28, 2008 Where are you pulling this variable from? $ch['r'.$num.''] You are defining variables outside of the function, then trying to use them inside the function. Instead you should pass those variables through the functions parameters, otherwise the function is only going to be good for about one use, and that defeats the entire purpose of a function. Quote Link to comment https://forums.phpfreaks.com/topic/93463-checktable-function/#findComment-478831 Share on other sites More sharing options...
Lamez Posted February 28, 2008 Author Share Posted February 28, 2008 oh, that is a good one to add to my notes $ch['r'.$num.''] will come from the table rnd1_check from the row r1 - r32, just depending on the number also how did you make that font all colorful without using the code tags? Quote Link to comment https://forums.phpfreaks.com/topic/93463-checktable-function/#findComment-478832 Share on other sites More sharing options...
Lamez Posted February 28, 2008 Author Share Posted February 28, 2008 alright I have edited my code, and I got it to work. Then I used it again on the same page, and both places where I used the function where blank, when the values where the same, here is the new code: <?php function checkTable($num, $a, $b){ $rnd = "rnd1_win"; $query = "SELECT * FROM `$rnd`"; $result = mysql_query($query); $win = mysql_fetch_array($result); $table = "rnd1_check"; $qu = "SELECT * FROM `$table`"; $re = mysql_query($qu); $ck = mysql_fetch_array($re); if ($ck['r'.$num.''] === ("0")){ echo "<select>"; echo '<option value="emp"></option>'; echo '<option value="'.$a.'">'.$a.'</option>'; echo '<option value="'.$b.'">'.$b.'</option>'; echo '</select>'; }else{ echo $win['$num']; } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/93463-checktable-function/#findComment-478844 Share on other sites More sharing options...
Baabu Posted February 28, 2008 Share Posted February 28, 2008 Well you are not doing the function in a proper way u should pass the function the table name also rather then providing two tables yourself and $ck['r'.$num.''] === ("0")) it is checking only ck what abt $win = mysql_fetch_array($result); the value might be in here but in short u r using functions in a wrong way Quote Link to comment https://forums.phpfreaks.com/topic/93463-checktable-function/#findComment-478865 Share on other sites More sharing options...
trq Posted February 28, 2008 Share Posted February 28, 2008 Not trying to be too harsh here, but I seriously think you need to start with some basics tutorials. You have no WHERE clause in your queries which meens you are lickely to end up with more than one row returned, yet you only ever use the first row. You could also likely get this done in one swift query if your intentions where a little clearer. Quote Link to comment https://forums.phpfreaks.com/topic/93463-checktable-function/#findComment-478873 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.