Board index   FAQ   Search  
Register  Login
Board index php forum :: php coding PHP coding => General

SELECT * from

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

SELECT * from

Postby Mikethk » Tue Oct 23, 2012 8:36 am

Hi.

Im pretty new at PHP.

How to ask for a specific selection?
Like SELECT * from newyork where day='2' AND month='feb' AND year='2013'";

I know how to archive the first where it selects day='2'";
But when i add month and year it wont work. What is the true code to archive the above?
Mikethk
New php-forum User
New php-forum User
 
Posts: 6
Joined: Tue Oct 23, 2012 8:30 am

Re: SELECT * from

Postby seandisanti » Tue Oct 23, 2012 1:06 pm

It completely depends on your database schema. show us what this outputs and someone can show you the way to filter your data.
Code: Select all
SELECT * FROM newyork LIMIT 1
seandisanti
php-forum Fan User
php-forum Fan User
 
Posts: 838
Joined: Mon Oct 01, 2012 12:32 pm

Re: SELECT * from

Postby Mikethk » Thu Oct 25, 2012 8:20 am

Oki i get this 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 'WHERE _day='2' AND _month='2' AND _year='2012'' at line 1


When i run this code:
Code: Select all
$query = "SELECT * FROM $region WHERE _day='2' AND _month='2' AND _year='2012'";



Is it an old syntax?
Mikethk
New php-forum User
New php-forum User
 
Posts: 6
Joined: Tue Oct 23, 2012 8:30 am

Re: SELECT * from

Postby egami » Thu Oct 25, 2012 8:33 am

Can you have a field name that starts with an underscore? seems odd.. you may have to escape that field name.. ie..


`fieldname` = 'value'
User avatar
egami
php-forum GURU
php-forum GURU
 
Posts: 2197
Joined: Wed Oct 06, 2010 11:19 am
Location: Happy Valley, UT

Re: SELECT * from

Postby Mikethk » Thu Oct 25, 2012 8:41 am

Oki i tried to do that:
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 'WHERE `_day`='2' AND `_month`='2' AND `_year`='2012'' at line 1


Seemed not to work. . . I think underscore works fine, cause when i:
Code: Select all
$query = "SELECT * FROM $region";
Then it works just fine.
Mikethk
New php-forum User
New php-forum User
 
Posts: 6
Joined: Tue Oct 23, 2012 8:30 am

Re: SELECT * from

Postby seandisanti » Thu Oct 25, 2012 8:42 am

what is the output when you grab a single row with the line i asked you to execute?
seandisanti
php-forum Fan User
php-forum Fan User
 
Posts: 838
Joined: Mon Oct 01, 2012 12:32 pm

Re: SELECT * from

Postby Mikethk » Thu Oct 25, 2012 9:26 am

seandisanti wrote:what is the output when you grab a single row with the line i asked you to execute?


Hi Seandisanti.

Im not sure i understand what i neda do.
I executed this:
Code: Select all
<?php
mysql_connect("mysql07.webdomain.dk","mk","uri") or die(mysql_error());
echo "Connected to MySQL<br /><hr />";
mysql_select_db("mikethk_dk") or die(mysql_error());
echo "Connected to Database<br /><hr />";
$query = "SELECT * FROM fyn LIMIT 1";
$result = mysql_query($query) or die(mysql_error());
while($row = mysql_fetch_array($result)) {
   echo $row['_arrangement'] . " - " . $row['_beskrivelse'];
   echo "<br />";
   }
?>


OBS: not right user and pass :)

The output from the above is:
SantaComming - ToTown
Which is correct.

What this what you needed? Im not sure i understand this "Schema" thing and how to retrieve it?
Mikethk
New php-forum User
New php-forum User
 
Posts: 6
Joined: Tue Oct 23, 2012 8:30 am

Re: SELECT * from

Postby seandisanti » Thu Oct 25, 2012 2:47 pm

the schema is the structure of the database and table. What i was tryign to get was a single valid row from your query (by removing the where conditions) so we can see the formatting and field names, and then re-write WHERE statement based on that new knowledge.
seandisanti
php-forum Fan User
php-forum Fan User
 
Posts: 838
Joined: Mon Oct 01, 2012 12:32 pm


Return to PHP coding => General

Who is online

Users browsing this forum: Google Feedfetcher and 2 guests

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.

cron