Jump to content

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?

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.