Forum Topic: Small mysql_query problem

(151 views • 6 replies)

This topic is 1 page long.

<< < > >>
None

WastedWizard

Reply To Post Reply & Quote

Posted at: 8/29/09 09:16 PM

WastedWizard EVIL LEVEL 21

Sign-Up: 01/08/05

Posts: 3,154

I'm a bit of a noob.

I'm trying to make a query that will find where left in the database is smaller than the current time.

This is the code I have come up with, i really don't have a clue with the WHERE left<$time") so yeah.

This is the code:

<?php

include 'dbc.php';

$time=time();

$end = mysql_query("SELECT * FROM round WHERE left<$time")
or die(mysql_error());

The error isss:

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 '<1251594569' at line 1

Any help would be really appreciated :).


None

WastedWizard

Reply To Post Reply & Quote

Posted at: 8/29/09 10:22 PM

WastedWizard EVIL LEVEL 21

Sign-Up: 01/08/05

Posts: 3,154

Ok realised i was an idiot and didn't put ; at end of the line.

So the new error is now

Parse error: syntax error, unexpected T_LOGICAL_OR in /home/warcomma/public_html/clocktime.


None

blah569

Reply To Post Reply & Quote

Posted at: 8/29/09 10:35 PM

blah569 DARK LEVEL 21

Sign-Up: 01/18/05

Posts: 2,706

Here are a few possible solutions:

If you want to use the current line that you're using, it should look like this:

$end = mysql_query("SELECT * FROM `round` WHERE `left` < '$time'")or die(mysql_error());

However, you said that you wanted to compare and see if it was similar. If you wanted to do that, then this might help out:

$end = mysql_query("SELECT * FROM `round` WHERE `left` LIKE '%$time%'")or die(mysql_error());

I'm not sure if that is what you wanted to do, however that would check if $time is located anywhere in left, but I don't think that's what you meant.

You might find that you will want to use a more precise error checking method later on for MySQL queries, as some additional text so you can know where to jump to the problem.

Good luck!

PHP: Main | AS3: Main | Get Firefox | Host large files (fast and free)!
"Thank you for learning me English."

BBS Signature

None

liljim

Reply To Post Reply & Quote

Posted at: 8/29/09 10:51 PM

liljim NEUTRAL LEVEL 27

Sign-Up: 12/16/99

Posts: 8,909

I'm sure I'll probably come in for some stick for this, but back ticks in queries are generally a workaround for a problem you've created for yourself and should never be necessary.

In this case, "LEFT" is a reserved word in mysql, and I wouldn't be surprised if "ROUND" ended up on that list at some point. Avoid using these words for tables and in columns in your tables.

http://dev.mysql.com/doc/refman/5.1/en/r eserved-words.html

Also, check out the date/time functions mysql provides you with.

BBS Signature

None

WastedWizard

Reply To Post Reply & Quote

Posted at: 8/29/09 10:51 PM

WastedWizard EVIL LEVEL 21

Sign-Up: 01/08/05

Posts: 3,154

Thank you so much. Your a legend.


None

WastedWizard

Reply To Post Reply & Quote

Posted at: 8/30/09 01:04 PM

WastedWizard EVIL LEVEL 21

Sign-Up: 01/08/05

Posts: 3,154

Ok now i'm even more confused lol.

$end = mysql_query("SELECT * FROM `round` WHERE `ends` > 'time()'")or die(mysql_error());

echo $end;

I did this just to test I got the right result.
And i got : Resource id #3 Not 1252195155 like it should?

Layout of database is in picture below.

Any help on what i have done wrong now? lol

Small mysql_query problem


None

citricsquid

Reply To Post Reply & Quote

Posted at: 8/30/09 01:10 PM

citricsquid DARK LEVEL 23

Sign-Up: 06/25/05

Posts: 16,110

I could be wrong, but when calling mysql results you need to take them from the resulting array. So, for example:

$query = mysql_query("SELECT * FROM table WHERE something='$something' LIMIT 1");

to get the result you'd need to do:

$query = mysql_query("SELECT * FROM table WHERE something='$something' LIMIT 1");
$row = mysql_fetch_array($query);
echo $row['something'];

Where "something" is what you want to return.


All times are Eastern Standard Time (GMT -5) | Current Time: 08:43 PM

<< Back

This topic is 1 page long.

<< < > >>
You need a Grounds Gold Account to post on the NG BBS! If you don't have one, click here to sign up now! It's fast, free, and easy — and opens up tons of great NG features!