SitePoint Sponsor |
|
User Tag List
Results 1 to 6 of 6
Thread: pull title from MySQL with PHP
-
Jan 5, 2001, 08:10 #1
- Join Date
- Nov 2000
- Location
- Hong Kong
- Posts
- 1,508
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
How would you pull the title out of a table in PHP, i tried
<?php echo('$title'); ?>
which down below i have said what title is, how ever it display the file name instead.??
-
Jan 5, 2001, 09:28 #2
- Join Date
- Jul 2000
- Location
- Warwickshire, England
- Posts
- 557
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
It is probably because $title is undefined. You must put a value in this variable before you try to print it's contents.
Just use a simple select statement and mysql fetch.
Remember, later in the script, if you already have a mysql connection, there is no need to establish another one.
-
Jan 5, 2001, 09:34 #3
- Join Date
- Nov 2000
- Location
- Hong Kong
- Posts
- 1,508
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
I have title defined later in the script...
Question: If you have opened a connection, and open another, does this slow the connection?
by opening a connection do you mean:
when you give ur username and password or something else?
-
Jan 5, 2001, 09:43 #4
- Join Date
- Jul 2000
- Location
- Warwickshire, England
- Posts
- 557
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Yep, mysql_connect or pconnect. You should never need to use the pconnect twice in a script.
Having more than one connection wont be noticable unless your site gets busy.. but remember when you have more than one, there is always going to be more memory needed than is necessary.
btw; if you need the $title defined before you use it..
e.g.
<?php
echo ($title);
$title = "hello world!";
?>
would return nothing..
whereas
<?php
$title = "hello world";
echo ($title);
?>
would return hello world.
Hope I understood / explained that correctly
-
Jan 5, 2001, 09:51 #5
- Join Date
- Nov 2000
- Location
- Hong Kong
- Posts
- 1,508
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
I got it.
ONe more question, should u use something at the end of a script to free memory or something?
-
Jan 5, 2001, 10:01 #6
- Join Date
- Jul 2000
- Location
- Warwickshire, England
- Posts
- 557
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
You can use mysql_free_result, but PHP automatically does it when the script ends, so I dont bother
mysql_free_result (int result)
Bookmarks