If mysql row post exist
Moderator: General Moderators
If mysql row post exist
Hi,
How can I make a php scrip that checks to see if there exist a post in a mysql row.
Fx:
If ROW contains data then echo "Row contains data"
Else if ROW not contains data then echo "Row don't contain any data"
Hope you understand
Best Regards,
Qaid
How can I make a php scrip that checks to see if there exist a post in a mysql row.
Fx:
If ROW contains data then echo "Row contains data"
Else if ROW not contains data then echo "Row don't contain any data"
Hope you understand
Best Regards,
Qaid
- shiznatix
- DevNet Master
- Posts: 2745
- Joined: Tue Dec 28, 2004 5:57 pm
- Location: Tallinn, Estonia
- Contact:
Code: Select all
$sql = 'SELECT * FROM table_name WHERE thing = "'.$var.'"';
$query = mysql_query($sql) or die(mysql_error());
if (mysql_num_rows($query) != 0)
echo 'supra sweet';//rows found
else
echo 'not very supra sweet, lets add some tang!';//no rows foundThis won't work... This will post "'supra sweet".
And if the row is empty it will post nothing,
Example:
Row called data store this inside "data"
Supra$row[data]hurra :: then I will get this output: Supradatahurra
Row called data stored nothing inside ""
Supra$row[data]hurra :: then I will get this output: Suprahurra
It won't post the else statement...
And if the row is empty it will post nothing,
Example:
Row called data store this inside "data"
Supra$row[data]hurra :: then I will get this output: Supradatahurra
Row called data stored nothing inside ""
Supra$row[data]hurra :: then I will get this output: Suprahurra
It won't post the else statement...
- Christopher
- Site Administrator
- Posts: 13596
- Joined: Wed Aug 25, 2004 7:54 pm
- Location: New York, NY, US
- dibyendrah
- Forum Contributor
- Posts: 491
- Joined: Wed Oct 19, 2005 5:14 am
- Location: Nepal
- Contact:
if this might help you
feyd | Please use
Dibyendra
feyd | Please use
Code: Select all
andCode: Select all
tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
I have made the simple function just to check the data if already exist on table or not.Code: Select all
/*
bool function if_exist( string table, string field, string data)
$table as database table
$field as table field to which we compare agains given data
$data as passed data to function to match with given field of table
*/
function if_exist($table, $field, $data){
$query = "select * from ". $table. " where ". $field . " = " . $data ;
if(mysql_num_rows(mysql_query($query))>0){
retun(true);
}else{
return(false);
}
}Dibyendra
feyd | Please use
Code: Select all
andCode: Select all
tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]Is it possible to check if a given data exist exactly as in the code...
Like this...
This won't work... 
Like this...
Code: Select all
$query = "SELECT * FROM table WHERE data = 'yes'";
if(@mysql_num_rows(mysql_query($query)) != yes){
echo "yes";
}else{
echo "No";
}- feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
mysql_num_rows() will not return 'yes' ever.
feyd wrote:mysql_num_rows() will not return 'yes' ever.
Code: Select all
/*
bool function if_exist( string table, string field, string data)
$table as database table
$field as table field to which we compare agains given data
$data as passed data to function to match with given field of table
*/
function if_exist($table, $field, $data){
$query = "select * from ". $table. " where ". $field . " = " . $data ;
if(mysql_num_rows(mysql_query($query))>0){
retun(true);
}else{
return(false);
}
}Best Regards.
Is it possible to check if a given data exist exactly as in the code...
Like this...
But with this code instead?
Like this...
Code: Select all
$query = "SELECT * FROM table WHERE data = 'yes'";
if(@mysql_num_rows(mysql_query($query)) != yes){
echo "yes";
}else{
echo "No";
}But with this code instead?
Code: Select all
/*
bool function if_exist( string table, string field, string data)
$table as database table
$field as table field to which we compare agains given data
$data as passed data to function to match with given field of table
*/
function if_exist($table, $field, $data){
$query = "select * from ". $table. " where ". $field . " = " . $data ;
if(mysql_num_rows(mysql_query($query))>0){
retun(true);
}else{
return(false);
}
}mysql_affected_rows();
feyd | Please use
feyd | Please use
Code: Select all
andCode: Select all
tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
i think this will helpCode: Select all
$resultado=mysql_query("select * from table where value = '".$value."' ";
$n=mysql_affected_rows();
if ($n > 0)
{
//HAS DATA
}
else{
//DOES NOT HAVE DATA
}feyd | Please use
Code: Select all
andCode: Select all
tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]