Jump to content

[SOLVED] Adding value to variable from databse content.


Bman900

Recommended Posts

I have a real simple thing here. In my database I have a table called site_title with a column called title

I inserted "Something here" when I ran the create table script so I can have sort of a default value there. Now I have a variable called $site_title that I want to fill with the entry that I just entered. The code I used so far is:

 

<?php

 

mysql_connect("changed", "changed", "changed") or die(mysql_error());

mysql_select_db("db283875085") or die(mysql_error());

 

$title = mysql_query("SELECT title FROM site_title");

 

echo "$title";

 

?>

 

I get a result of Resource id #2

 

How would I get to display the "Something here" that I instered into my database?

<?php

mysql_connect("changed", "changed", "changed") or die(mysql_error());
mysql_select_db("db283875085") or die(mysql_error());

$titleRes = mysql_query("SELECT title FROM site_title");
$title = mysql_result($titleRes, 0, 0);

echo "$title";

?>

 

For a one column pull mysql_result works. For multiple rows/columns mysql_fetch_assoc would be the way to go.

<?php

mysql_connect("changed", "changed", "changed") or die(mysql_error());
mysql_select_db("db283875085") or die(mysql_error());

$titleRes = mysql_query("SELECT title FROM site_title");
$title = mysql_result($titleRes, 0, 0);

echo "$title";

?>

 

For a one column pull mysql_result works. For multiple rows/columns mysql_fetch_assoc would be the way to go.

 

I just want to understand something. In this line:

 

$title = mysql_result($titleRes, 0, 0);

 

Now the first 0 is the row id right? What is the second 0 for?

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.