Jump to content

Recommended Posts

I need help again.  I'm trying to search a table named `Photos`, in a field named `PhotoDate`, for any photos taken on a specific month and day, regardless of year.  I need a wildcard, or some method of ignoring the year.  The field `PhotoDate` is in the format "2007-04-17" of type varchar(10).  Of all of my attempts, this one doesn't return any mySQL errors, but it comes up blank with the message "Query was empty".  I would like to have the query return the values contained in fields `PhotoID`, `City`, `State`, and `PhotoDate`.

 

<?

$sql = "SELECT * FROM `Photos` WHERE `PhotoDate` LIKE CONVERT(_utf8 \'%%%%-04-17\' USING latin1) COLLATE latin1_swedish_ci";

$result = mysql_query($query) or die(mysql_error());

while(list($PhotoID) = mysql_fetch_row($result))

{

  echo "$PhotoID, $City, $State, $PhotoDate<br>";

}

?>

 

Can someone please tell me what I am doing wrong?

 

Thanks,

Stan

 

Link to comment
https://forums.phpfreaks.com/topic/47424-solved-message-query-was-empty/
Share on other sites

I made the changes, but that got me back to the mySQL error message:

 

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '\'%%%%-04-17\' USING latin1) COLLATE latin1_swedish_ci' at line 1.

 

Stan

 

I got that from doing a manual search via phpMyAdmin, where it said, "Or Do a "query by example" (wildcard: "%")".  The search returned the SQL query that said:

 

SELECT *

FROM `Photos`

WHERE `PhotoDate` LIKE CONVERT( _utf8 '%%%%-04-17'

USING latin1 )

COLLATE latin1_swedish_ci

LIMIT 0 , 30

 

When I clicked generate PHP code, I got:

$sql = 'SELECT * FROM `Photos` WHERE `PhotoDate` LIKE CONVERT(_utf8 \'%%%%-04-17\' USING latin1) COLLATE latin1_swedish_ci';

 

Stan

 

re: "Why are you converting on the fly anyways ?" 

 

Because I don't know any better.

 

I did finally get it to work, turns out that the problem was the \ in the condition:

LIKE CONVERT(_utf8 \'%%%%-04-17\' USING latin1)

 

With some additions, here's what works now:

 

<?

echo "<table border>";

echo "<tr><th>Search</th><th>PhotoID</th><th>FileName</th><th>City</th><th>State</th><th>Date</th></tr>";

$query = "SELECT * FROM `Photos` WHERE `PhotoDate` LIKE CONVERT(_utf8 '%%%%-04-17' USING latin1) COLLATE latin1_swedish_ci ORDER BY PhotoDate";

$result = mysql_query($query) or die(mysql_error());

while(list($PhotoID, $FileName, $RosterID, $UserID, $City, $State, $PhotoDate, $PhotoAdded, $Remarks, $Views, $Active, $Resubmit) = mysql_fetch_row($result))

{

echo "<tr>";

echo "<td><a href='PhotoDetails.php?PhotoID=$PhotoID'>Search</a></td>";

echo "<td>$PhotoID</td>";

echo "<td>$FileName</td>";

echo "<td>$City</td>";

echo "<td>$State</td>";

echo "<td>$PhotoDate</td>";

  echo "</tr>";

}

echo "</table>";

?>

 

If there is a better way, I'm open to it.

 

Thanks for the help,

Stan

 

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.