Jump to content

Recommended Posts

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.

Link to comment
https://forums.phpfreaks.com/topic/89462-mixture-of-php-and-mysql/
Share on other sites

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/

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.

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;
}
}

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?

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.