Jump to content

[SOLVED] will this query statement work?


jim.davidson

Recommended Posts

Ok I trued it

 

$userid = 1;

 

  mysql_select_db($database_mine, $mine);

  $query_getCust = sprintf("SELECT * FROM customer WHERE updated_by = %s OR created_by =%s", GetSQLValueString($userid, "int"));

  $getCust = mysql_query($query_getCust, $mine) or die(mysql_error());

  $row_getCust = mysql_fetch_assoc($getCust);

  $totalRows_getCust = mysql_num_rows($getCust);

echo $totalRows_getCust;

 

Here's the error I'm getting.

 

Warning: sprintf() [function.sprintf]: Too few arguments in C:\Sites\shoppe\testsql.php on line 38

Query was empty

 

 

Sorry I meant to say tried, no trued.  Also this is line 38

 

$query_getCust = sprintf("SELECT * FROM customer WHERE updated_by = %s OR created_by = %s", GetSQLValueString($userid, "int"));

 

I think it has to do with GetSQLValueString($userid, "int"), I'm pretty sure I'm missing something here.

 

Any help will be appreciated

 

Hi

 

Don't normally use sprintf, but it appears you are using 2 parameters in the SQL but only only passing one.

 

So this would work (although horrible and pointless):-

 

$query_getCust = sprintf("SELECT * FROM customer WHERE updated_by = %s OR created_by = %s", GetSQLValueString($userid, "int"), GetSQLValueString($userid, "int"));

 

However not sure but think this would work and is better

 

$query_getCust = sprintf("SELECT * FROM customer WHERE updated_by = %1$s OR created_by = %1$s", GetSQLValueString($userid, "int"));

 

All the best

 

Keith

Ok I tried a different route,

$userid = 1;

$query_getCust = "SELECT * FROM customer WHERE updated_by = $userid OR created_by = $userid";

  $row_getCust = mysql_fetch_assoc($getCust);

  $totalRows_getCust = mysql_num_rows($getCust);

  echo $totalRows_getCust;

 

$totalRows_getCust equaled 4 and thats the correct total

 

Am I asking for trouble going this way? I'm new to this and learning as I go.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.