Jump to content

TOTAL NOOB needs some directions I think


Scabby

Recommended Posts

Hey folks,

 

Ok so I programmed when I was young and now I would like to brush up on php but I'm having problems kick starting. I have set myself the task of a simple database query and I cannot get moving with this.

 

<?php
//Open a connection to the mysql server
$link=mysql_connect("localhost","scabby","scooby");
if(!$link) {
	print("Failed to establish connection to mysql server!");
	exit();
}
//Select the database
$status=mysql_select_db("scabby");


//Get town from User *************to do*****************

//Temporary Measure, Town inserted here!
$rq="Dudley"

//Run query

$query="SELECT Town,Address_time FROM customers WHERE Town=$rq";
$rs=mysql_query($query);
if(!$rs) {
	print("Query Error: ".mysql_error());
}
$numrows=mysql_num_rows($rs);
print("Number of rows returned: $numrows <br /> ");
$customer=mysql_fetch_assoc($rs);
print($customer['Town']);
print($customer['Address_time']);

?>

 

This is where I have got to but I think where I'm getting stuck here is the relation between the variables.

take the line

 

$query="SELECT Town,Address_time FROM customers WHERE Town=$rq";

 

It will not accept this and I don't know why. What I'm trying to achieve is to retrieve the records whos town is contained in the query variable.

 

I think I'm missing something in the fundamentals as I dragged myself through Basic and Opcode programming, this seems to handle variables differently.

 

Anyone some help here, or some nifty little reading that will iron over the foundations of what you need to know to get your head around this.!!

 

cheers Guys

Link to comment
Share on other sites

Do you get any errors?

Try:

$query= "SELECT Town,Address_time FROM customers WHERE Town='{$rq}'";

Also this:

//Temporary Measure, Town inserted here!
$rq="Dudley"

//Run query

Should be:

//Temporary Measure, Town inserted here!
$rq = "Dudley";

//Run query

Link to comment
Share on other sites

Thanks for the reply papface.

 

So what is returned exactly from the line

 

$query= "SELECT Town,Address_time FROM customers WHERE Town='{$rq}'";

 

what does $query contain

 

$query is a variable that contains the entire line of code ""SELECT Town,Address_time FROM customers WHERE Town='{$rq}'";"

 

That is a basic must know for PHP, check out some books or online tutorials.

Link to comment
Share on other sites

Yes a stupid request $query= states itself doesn't it. I move slowly but I always get there.

 

Thanks for the replies, they are very much appreciated.

 

I got my head around Joomla a while back and when I started to teach myself that I was held up for quite a while on simple things. Things that you could get answered in a few mins over a coffee with someone.

 

Thats why I say thanks for what may seem to some a stupid question.

Link to comment
Share on other sites

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.