Jump to content

[SOLVED] Please Help A Newbie... Simple Question With Mysql Where


Looktrne

Recommended Posts

Hello Im Paul

 

I Am Trying To Update A Database With Other Parts Of The Database

 

$mi="members id from another table"

 

Could you tell me why this querry is not executing??? is it a syntax problem?

 

I need to select the state field from dt_profile where the member id equals the id in $mi

 

$result = mysql_query("SELECT * FROM dt_profile

WHERE member_id='$mi'")

 

Any help would be greatly appreciated...

 

thanks

 

Paul

Link to comment
Share on other sites

The syntax looks OK. But if you only want the state field, specify that and not "*" or you just slow things down.

$result = mysql_query("SELECT state FROM dt_profile
                               WHERE member_id='$mi'");

 

And, if you want to know why a query isn't working, let mysql tell you.

$result = mysql_query("SELECT * FROM dt_profile
                              WHERE member_id='$mi'")
                              or die (mysql_error());

Link to comment
Share on other sites

ok I tried this

 

but when I echo result

 

instead of showing a state it just says resource ID#

 

and keeps counting

 

how do I actually turn the result into the state so I can update the state in another table??

 

thanks for helping

 

ok lemme simplify this a little

 

the table dt_matchfinder had a state field

 

I need to take the state field from dt_profile table and update the dt_matchfinder with this state

 

making sure the member_id matches

 

the problem is the dt_matchfinder table has null set for many of the state field but in the dt_profile each member ID has a specific state and I need the same to be true in the dt_matchfinder table

 

A code example would be greatly appreciated

 

Have a great holiday weekend

 

Paul

Link to comment
Share on other sites

the code does not exist yet here is something I wrote

 

$sql="SELECT * FROM dt_matchfinder;";

$result=mysql_query($sql);

 

 

while($row=mysql_fetch_assoc($result)){

$ms=$row['state'];

echo "Id= state is:".$ms;

 

this will pull all the states set in the dt_matchfinder only problem is only like 10 % are set

 

I need to pull state from dt_profile with the member_id from dt_profile

 

and place that state into the state of dt_matchfinder with same member_id

 

Sorry If seems confusing but thats as simple as I can put it they both have state fields and both have member_id fields I need the states from dt_profile to update the states in dt_matchfinder where the member_id is the same

 

thanks again for helping

 

total newbie

 

Paul

Link to comment
Share on other sites

A little bit confusion ok :

 

U want to pullout state from dt_profile table then why u use this:

$sql="SELECT * FROM dt_matchfinder;";

 

Do it like this:

$sql="SELECT state FROM dt_profile where member_id='$mid';";
$result=mysql_query($sql);


while($row=mysql_fetch_assoc($result)){
$ms=$row['state'];
echo "Id= state is:".$ms;

 

Than update ur dt_matchfinder table with this state like:

$sql="Update dt_matchfinder set state='$ms' where memberid='$mid';";
$result=mysql_query($sql);

Link to comment
Share on other sites

oh sounds like this is what I will try to use

 

but still not sure if this is the easiest way

 

I need a loop

 

to scan all the member_id in the dt_profile and grab there states

 

then to write all those states into dt_matchfinder according to member id...

 

is there more code I need or is what you gave me going to do all this?

 

sorry to be such a pain but I am really new and I dont even understand alot of the therory behind some of the lines especially how the loops is going to work

 

Paul

Link to comment
Share on other sites

This is what I am trying to do

 

but when I add the update lines in the script does not run if I run without the second $result it displays the member id and state

 

these are the two variables I need to update the other table dt_matchfinder.... to update the state where the member_id= the one in dt_profile

 

am I trying to run multiply querrys in a invalid way???? I dunno

 

help please I know im getting close

 

:)

 

Paul

Link to comment
Share on other sites

wow! that was too easy

 

I was thinking I had to run a while loop

 

when mysql could do all that so easy

 

I really need to read a book :)

 

thanks alot... but im not sure I learned much you made it so easy... anyway one quick question

 

do the index keys need to be updated after making that change??? because all the tables where indexed at some point in the past.. but it seems I only had to run that optimization script once and the database has been cruising right along.....

 

anyway thanks again

 

and do let me know on the index key thing

 

Paul :)

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.