Lamez Posted February 5, 2008 Share Posted February 5, 2008 Can I do a if statement to tell if the user is also in another table? The user is in the default table, but if he is in the paid table, make a link, if not make a check box. How would I be able to do this? -- Also How do I make it where the user can only be in the table once? because I have a table, and every time I submit data, even though the user is already in there, it adds them again. Quote Link to comment https://forums.phpfreaks.com/topic/89462-mixture-of-php-and-mysql/ Share on other sites More sharing options...
monkeytooth Posted February 5, 2008 Share Posted February 5, 2008 Well no simple answers to this.. Yes its possible to use an if statement to compare to different rows in a table. It is also possible to do a check box for one and a link for another. As how to do it, its a little bit more complex then a simple answer that involves your database's layout for starters.. How to find out if a user is in one table or another, or already in the table.. best bet is to check to see if the user exists before inserting into the database. If the user already exists you might want to use update rather then insert.. Again there are no simple answers. here is a great tutorial site.. for php and mysql usage as well as other things like AJAX JAVA CSS, etc.. http://www.tizag.com/mysqlTutorial/ Quote Link to comment https://forums.phpfreaks.com/topic/89462-mixture-of-php-and-mysql/#findComment-458169 Share on other sites More sharing options...
revraz Posted February 5, 2008 Share Posted February 5, 2008 Search on my posts for checkunique, I posted a function the other day. You need to query the table first to see if they exist. Also How do I make it where the user can only be in the table once? because I have a table, and every time I submit data, even though the user is already in there, it adds them again. Quote Link to comment https://forums.phpfreaks.com/topic/89462-mixture-of-php-and-mysql/#findComment-458272 Share on other sites More sharing options...
Lamez Posted February 5, 2008 Author Share Posted February 5, 2008 Revraz is this the function you are talking about? function checkUnique($table, $field, $compared){ if (get_magic_quotes_gpc()) { $table = stripslashes($table); $field = stripslashes($field); $compared = stripslashes($compared); } $table = mysql_real_escape_string($table); $field = mysql_real_escape_string($field); $compared = mysql_real_escape_string($compared); $result = mysql_query("SELECT $field FROM $table WHERE $field = '$compared'"); if(mysql_num_rows($result)==0) { return TRUE; } else { return FALSE; } } Quote Link to comment https://forums.phpfreaks.com/topic/89462-mixture-of-php-and-mysql/#findComment-458310 Share on other sites More sharing options...
Lamez Posted February 5, 2008 Author Share Posted February 5, 2008 ok I made this code: <form action="pay_do.php" method="post"> <table width="100%" border="0"> <tr> <td width="419"><strong>First Name </strong></td> <td width="487"><strong>Last Name </strong></td> <td width="257"><strong>Paid (username) </strong></td> </tr> <? $qr=mysql_query("select * from users order by first"); $pt=mysql_query("select * from paid order by user"); while ($rs=mysql_fetch_assoc($qr)) { $pu=mysql_fetch_assoc($pt) ?> <tr> <td><? echo $rs['first'];?></td> <td><? echo $rs['last'];?></td> <td> <? if ($pu['user'] == ($rs['username'])){ print '<a href="new">Not Paid</a> '; }else{ ?> <input type="checkbox" name="checkbox[]" onchange="if(this.checked) { this.value='<?=$rs['username'] ?>'; } else { this.value=''; }" /> <? } ?> (<? echo $rs['username']; ?>) </td> <? } ?> </tr> </table> <br /> <input name="Submit" type="Submit" value="Mark Paid" /> </form> When I select the admin, it adds him to the table paid, then when I go back it shows the link, not the checkbox, but then when I submit googlebot, it comes back, and they are both checkboxs, what is wrong? Quote Link to comment https://forums.phpfreaks.com/topic/89462-mixture-of-php-and-mysql/#findComment-458344 Share on other sites More sharing options...
Lamez Posted February 5, 2008 Author Share Posted February 5, 2008 any ideas? Quote Link to comment https://forums.phpfreaks.com/topic/89462-mixture-of-php-and-mysql/#findComment-458663 Share on other sites More sharing options...
revraz Posted February 5, 2008 Share Posted February 5, 2008 Yes Revraz is this the function you are talking about? Quote Link to comment https://forums.phpfreaks.com/topic/89462-mixture-of-php-and-mysql/#findComment-458706 Share on other sites More sharing options...
Lamez Posted February 5, 2008 Author Share Posted February 5, 2008 so where it says return true, that is where I want to put my link, and the false is the checkbox Quote Link to comment https://forums.phpfreaks.com/topic/89462-mixture-of-php-and-mysql/#findComment-459141 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.