Jump to content

Recommended Posts

What database engine are you using (for instance MySQL).  Can we see a query?  Can we see code you've written?  Do you know SQL so you can get that data out?  More information is helpful here.  To give you an idea though.

 

// database connection here

$sql = "SELECT cell FROM table WHERE id='$id'";
$r = mysql_fetch_assoc(mysql_query($sql));

// reference data through the $r['cell'] variable

Link to comment
https://forums.phpfreaks.com/topic/181292-cells/#findComment-956446
Share on other sites

Oh yes, I'm sorry. I'm using MySQL.

 

So say if I wanted to extract a value in a certain column in a certan row using a user ID. (Say for instance, the email address for a certain user and then store that email address in variable $address, so that I could easily create html with that variable)

 

Does that make much sense? I'm pretty knew to MySQL so I don't know much of any code in PHP to accesse my databases.

Link to comment
https://forums.phpfreaks.com/topic/181292-cells/#findComment-956459
Share on other sites

pretty much what s0c0 said.

$sql = "SELECT email FROM table WHERE id=$id LIMIT 1";//limit to 1 row returned
$query = mysql_query($sql);
$row = mysql_fetch_assoc($query);//could also use fetch_array or fetch_row i guess, but i prefer fetch_assoc
$cell = $row['email'];//$cell now contains the email address

 

just replace table with your table name, and id with whatever the userID column is, and obviously $id with whatever variable you are using that stores the id of the row you want to access

 

Link to comment
https://forums.phpfreaks.com/topic/181292-cells/#findComment-956463
Share on other sites

You need to establish a mysql connection first.  It may be helpful for you to get a book from the library on php mysql.  I learned from this book many years ago and it did wonders for my career: http://www.amazon.com/gp/product/0672329166/ref=pd_lpo_k2_dp_sr_1/190-7625085-1967410?pf_rd_m=ATVPDKIKX0DER&pf_rd_s=lpo-top-stripe-1&pf_rd_r=17DBYJW757PXX0S7B2V3&pf_rd_t=201&pf_rd_p=486539851&pf_rd_i=0672317842 its called PHP and MySQL Web Development.

 

For information on mysql connections:

http://php.net/manual/en/function.mysql-connect.php

Link to comment
https://forums.phpfreaks.com/topic/181292-cells/#findComment-956492
Share on other sites

Oh yes, I know a small amount about SQL and I can connect with my database and such.

 

Quick question: is $row a designated php variable? I've used this before and I didn't know if I could change it or if it stands for something special.

 

Also, if I wanted to do something similar to this (with say, password) would I need to rename all these variables differently? or could I leave $sql/$query/$row?

 

Thanks again everyone for the help!

Link to comment
https://forums.phpfreaks.com/topic/181292-cells/#findComment-956497
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.