Monk3h Posted June 25, 2008 Share Posted June 25, 2008 I have put an id statement as a function as shown below. The idea for this is so that every time that function is displayed the Funsction is repeated. I will be using this becasue some of the variables will be redefined every now and then so the funsction will need to be repeated. function idcheck() { $check = mysql_fetch_array(mysql_query("SELECT * FROM `alphaground` WHERE `id` = '$id'")); if ($check[ownerid] == 0){ Print "<img src= images/keyneautural.png>"; }else{ Print "<img src= images/keyalliance.png>"; }} // LINE 7 The problem with this code is that when the ownerid feild dosnt == 0 it still prints the image for the 0 and not the else. :s Fatal error: Cannot redeclare idcheck() (previously declared in /home/monk3h/public_html/projectalpha/alphaground.php: in /home/monk3h/public_html/projectalpha/header.php on line 18 Link to comment https://forums.phpfreaks.com/topic/111830-solved-function-not-working/ Share on other sites More sharing options...
sasa Posted June 25, 2008 Share Posted June 25, 2008 you must pass variable $id to function naw value of $id is '' (null) and you query looks SELECT * FROM `alphaground` WHERE `id` = '' it not return any row $check is empty array and $check['ovnerid'] has no value Link to comment https://forums.phpfreaks.com/topic/111830-solved-function-not-working/#findComment-574047 Share on other sites More sharing options...
Monk3h Posted June 25, 2008 Author Share Posted June 25, 2008 This is my full script, it looks big. but its just a huge 11X11 table. How would i change this script so that after $id is redefined the function is done again and checks too see whaty image to use? as you can see $id is redefined 121 times. <?php include ("header.php"); function idcheck() { $check = mysql_fetch_array(mysql_query("SELECT * FROM `alphaground` WHERE `id` = '$id'")); if ($check[ownerid] == 0){ Print "<img src= images/keyneautural.png>"; }else{ Print "<img src= images/keyalliance.png>"; }} Print" <table width='210' border='0' align='center' cellpadding='0' cellspacing='0'> <tr> <td><table width='350' height='350' border='0' align='center' cellpadding='0' cellspacing='0'> <tr> <td width='30' height='350' rowspan='3' background='images/mapleft.png'></td> <td width='290' height='30' background='images/maptop.png'></td> <td width='30' height='350' rowspan='3' background='images/mapright.png'></td> </tr> <tr> <td width='290' height='290' bgcolor='#66CCFF'><table width='210' border='0' align='center' cellpadding='0' cellspacing='0'> <tr> <td>"; $id = 1; idcheck(); Print" </td> <td>"; $id = 2; idcheck(); Print" </td> <td>"; $id = 3; idcheck(); Print" </td> <td>"; $id = 4; idcheck(); Print" </td> <td>"; $id = 5; idcheck(); Print" </td> <td>"; $id = 6; idcheck(); Print" </td> <td>"; $id = 7; idcheck(); Print" </td> <td>"; $id = 8; idcheck(); Print" </td> <td>"; $id = 9; idcheck(); Print" </td> <td>"; $id = 10; idcheck(); Print" </td> <td>"; $id = 11; idcheck(); Print" </td> </tr> <tr> <td>"; $id = 12; idcheck(); Print" </td> <td>"; $id = 13; idcheck(); Print" </td> <td>"; $id = 14; idcheck(); Print" </td> <td>"; $id = 15; idcheck(); Print" </td> <td>"; $id = 16; idcheck(); Print" </td> <td>"; $id = 17; idcheck(); Print" </td> <td>"; $id = 18; idcheck(); Print" </td> <td>"; $id = 19; idcheck(); Print" </td> <td>"; $id = 20; idcheck(); Print" </td> <td>"; $id = 21; idcheck(); Print" </td> <td>"; $id = 22; idcheck(); Print" </td> </tr> <tr> <td>"; $id = 23; idcheck(); Print" </td> <td>"; $id = 24; idcheck(); Print" </td> <td>"; $id = 25; idcheck(); Print" </td> <td>"; $id = 26; idcheck(); Print" </td> <td>"; $id = '27'; idcheck(); Print" </td> <td>"; $id = 28; idcheck(); Print" </td> <td>"; $id = 29; idcheck(); Print" </td> <td>"; $id = 30; idcheck(); Print" </td> <td>"; $id = 31; idcheck(); Print" </td> <td>"; $id = 32; idcheck(); Print" </td> <td>"; $id = 33; idcheck(); Print" </td> </tr> <tr> <td>"; $id = 34; idcheck(); Print" </td> <td>"; $id = 35; idcheck(); Print" </td> <td>"; $id = 36; idcheck(); Print" </td> <td>"; $id = 37; idcheck(); Print" </td> <td>"; $id = 38; idcheck(); Print" </td> <td>"; $id = 39; idcheck(); Print" </td> <td>"; $id = 40; idcheck(); Print" </td> <td>"; $id = 41; idcheck(); Print" </td> <td>"; $id = 42; idcheck(); Print" </td> <td>"; $id = 43; idcheck(); Print" </td> <td>"; $id = 44; idcheck(); Print" </td> </tr> <tr> <td>"; $id = 45; idcheck(); Print" </td> <td>"; $id = 46; idcheck(); Print" </td> <td>"; $id = 47; idcheck(); Print" </td> <td>"; $id = 48; idcheck(); Print" </td> <td>"; $id = 49; idcheck(); Print" </td> <td>"; $id = 50; idcheck(); Print" </td> <td>"; $id = 51; idcheck(); Print" </td> <td>"; $id = 52; idcheck(); Print" </td> <td>"; $id = 53; idcheck(); Print" </td> <td>"; $id = 54; idcheck(); Print" </td> <td>"; $id = 55; idcheck(); Print" </td> </tr> <tr> <td>"; $id = 56; idcheck(); Print" </td> <td>"; $id = 57; idcheck(); Print" </td> <td>"; $id = 58; idcheck(); Print" </td> <td>"; $id = 59; idcheck(); Print" </td> <td>"; $id = 60; idcheck(); Print" </td> <td>"; $id = 61; idcheck(); Print" </td> <td>"; $id = 62; idcheck(); Print" </td> <td>"; $id = 63; idcheck(); Print" </td> <td>"; $id = 64; idcheck(); Print" </td> <td>"; $id = 65; idcheck(); Print" </td> <td>"; $id = 66; idcheck(); Print" </td> </tr> <tr> <td>"; $id = 67; idcheck(); Print" </td> <td>"; $id = 68; idcheck(); Print" </td> <td>"; $id = 69; idcheck(); Print" </td> <td>"; $id = 70; idcheck(); Print" </td> <td>"; $id = 71; idcheck(); Print" </td> <td>"; $id = 72; idcheck(); Print" </td> <td>"; $id = 73; idcheck(); Print" </td> <td>"; $id = 74; idcheck(); Print" </td> <td>"; $id = 75; idcheck(); Print" </td> <td>"; $id = 76; idcheck(); Print" </td> <td>"; $id = 77; idcheck(); Print" </td> </tr> <tr> <td>"; $id = 78; idcheck(); Print" </td> <td>"; $id = 79; idcheck(); Print" </td> <td>"; $id = 80; idcheck(); Print" </td> <td>"; $id = 81; idcheck(); Print" </td> <td>"; $id = 82; idcheck(); Print" </td> <td>"; $id = 83; idcheck(); Print" </td> <td>"; $id = 84; idcheck(); Print" </td> <td>"; $id = 85; idcheck(); Print" </td> <td>"; $id = 86; idcheck(); Print" </td> <td>"; $id = 87; idcheck(); Print" </td> <td>"; $id = 88; idcheck(); Print" </td> </tr> <tr> <td>"; $id = 89; idcheck(); Print" </td> <td>"; $id = 90; idcheck(); Print" </td> <td>"; $id = 91; idcheck(); Print" </td> <td>"; $id = 92; idcheck(); Print" </td> <td>"; $id = 93; idcheck(); Print" </td> <td>"; $id = 94; idcheck(); Print" </td> <td>"; $id = 95; idcheck(); Print" </td> <td>"; $id = 96; idcheck(); Print" </td> <td>"; $id = 97; idcheck(); Print" </td> <td>"; $id = 98; idcheck(); Print" </td> <td>"; $id = 99; idcheck(); Print" </td> </tr> <tr> <td>"; $id = 100; idcheck(); Print" </td> <td>"; $id = 101; idcheck(); Print" </td> <td>"; $id = 102; idcheck(); Print" </td> <td>"; $id = 103; idcheck(); Print" </td> <td>"; $id = 104; idcheck(); Print" </td> <td>"; $id = 105; idcheck(); Print" </td> <td>"; $id = 106; idcheck(); Print" </td> <td>"; $id = 107; idcheck(); Print" </td> <td>"; $id = 108; idcheck(); Print" </td> <td>"; $id = 109; idcheck(); Print" </td> <td>"; $id = 110; idcheck(); Print" </td> </tr> <tr> <td>"; $id = 111; idcheck(); Print" </td> <td>"; $id = 112; idcheck(); Print" </td> <td>"; $id = 113; idcheck(); Print" </td> <td>"; $id = 114; idcheck(); Print" </td> <td>"; $id = 115; idcheck(); Print" </td> <td>"; $id = 116; idcheck(); Print" </td> <td>"; $id = 117; idcheck(); Print" </td> <td>"; $id = 118; idcheck(); Print" </td> <td>"; $id = 119; idcheck(); Print" </td> <td>"; $id = 120; idcheck(); Print" </td> <td>"; $id = 121; idcheck(); Print" </td> </tr> </table></td> </tr> <tr> <td width='290' height='30' background='images/mapbottom.png'></td> </tr> </table></td> <td><img src='images/key.png' width='200' height='300' /></td> </tr> </table> "; Print "<br><center><img src= images/actions.png> $id</center>"; include ("footer.php"); ?> Link to comment https://forums.phpfreaks.com/topic/111830-solved-function-not-working/#findComment-574049 Share on other sites More sharing options...
zenag Posted June 25, 2008 Share Posted June 25, 2008 try this... function idcheck($id) { $check = mysql_fetch_array(mysql_query("SELECT * FROM `alphaground` WHERE `id` = '$id'")); if ($check["ownerid"] == 0){ Print "<img src= images/keyneautural.png>"; }else{ Link to comment https://forums.phpfreaks.com/topic/111830-solved-function-not-working/#findComment-574052 Share on other sites More sharing options...
sasa Posted June 25, 2008 Share Posted June 25, 2008 change function to function idcheck($id) { $check = mysql_fetch_array(mysql_query("SELECT * FROM `alphaground` WHERE `id` = '$id'")); if ($check[ownerid] == 0){ Print "<img src= images/keyneautural.png>"; }else{ Print "<img src= images/keyalliance.png>"; }} and call function <td>"; $id = 1; idcheck($id); Print" </td> <td>"; $id = 2; idcheck($id); Print" </td> <td>"; $id = 3; idcheck($id); Print" </td> <td>"; $id = 4; idcheck($id); Print" </td> etc Link to comment https://forums.phpfreaks.com/topic/111830-solved-function-not-working/#findComment-574053 Share on other sites More sharing options...
Monk3h Posted June 25, 2008 Author Share Posted June 25, 2008 Fatal error: Cannot redeclare idcheck() (previously declared in /home/monk3h/public_html/projectalpha/alphaground.php:6) in /home/monk3h/public_html/projectalpha/header.php on line 18 Link to comment https://forums.phpfreaks.com/topic/111830-solved-function-not-working/#findComment-574055 Share on other sites More sharing options...
zenag Posted June 25, 2008 Share Posted June 25, 2008 <td>"; $id = 1; idcheck('1'); Print" </td> ......like that Link to comment https://forums.phpfreaks.com/topic/111830-solved-function-not-working/#findComment-574057 Share on other sites More sharing options...
Monk3h Posted June 25, 2008 Author Share Posted June 25, 2008 Thanks guys!! It works now. Link to comment https://forums.phpfreaks.com/topic/111830-solved-function-not-working/#findComment-574064 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.