•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the PHP section within the Web Development category of DaniWeb, a massive community of 423,717 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,154 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our PHP advertiser: Lunarpages PHP Web Hosting
Views: 1832 | Replies: 2
![]() |
•
•
Join Date: Jul 2005
Posts: 1
Reputation:
Rep Power: 0
Solved Threads: 0
Ok, I am fairly new to php, so please bear with me if I have done something stupid.
I am trying to write a CMS, right now I am writing a piece of code to get the article title from the database. I used
to call the database, and when I do, nothing comes up. When I tell it to pull from printtitle, I get recourse id #4. There are things in the database. Any help would be great.
I am trying to write a CMS, right now I am writing a piece of code to get the article title from the database. I used
<?
include('dbconnect.php');
//Get the article title
function article_title ()
{
$getarticletitlequery = "select title from article where id='$id'";
$printtitle = mysql_query($getarticletitlequery);
$fetchtitle = @mysql_fetch_object($printtitle);
$fetchtitle = ucfirst(strtolower($fetchtitle));
echo("$fetchtitle");
}
?>to call the database, and when I do, nothing comes up. When I tell it to pull from printtitle, I get recourse id #4. There are things in the database. Any help would be great.
•
•
Join Date: Jun 2005
Location: Kansas City, Missouri, USA
Posts: 344
Reputation:
Rep Power: 4
Solved Threads: 4
It is easier for me to simply post a good, working code example rather than debug yours, so here is a simple example of how to connect and query data from a MySQL database using PHP.
[PHP]
<?php
$db_server = "localhost";
$db_user = "root"; //Change if your username is not 'root'.
$db_pwd = ""; //Enter your password here.
$db_db = "mysql"; //Change to the database name you want to use.
if (!$cnn = mysql_connect($db_server, $db_user, $db_pwd)) {
echo mysql_error();
exit();
}
if (!mysql_select_db($db_db, $cnn)) {
echo mysql_error();
exit();
}
$sql = "select help_category_id, name from help_category";
if (!$res = mysql_query($sql, $cnn)) {
echo mysql_error();
exit();
}
while ($row = mysql_fetch_array($res, MYSQL_ASSOC)) {
echo "<br>".$row['name']." (".$row['help_category_id'].")\n";
}
?>
[/PHP]
[PHP]
<?php
$db_server = "localhost";
$db_user = "root"; //Change if your username is not 'root'.
$db_pwd = ""; //Enter your password here.
$db_db = "mysql"; //Change to the database name you want to use.
if (!$cnn = mysql_connect($db_server, $db_user, $db_pwd)) {
echo mysql_error();
exit();
}
if (!mysql_select_db($db_db, $cnn)) {
echo mysql_error();
exit();
}
$sql = "select help_category_id, name from help_category";
if (!$res = mysql_query($sql, $cnn)) {
echo mysql_error();
exit();
}
while ($row = mysql_fetch_array($res, MYSQL_ASSOC)) {
echo "<br>".$row['name']." (".$row['help_category_id'].")\n";
}
?>
[/PHP]
[php]
<?
include('dbconnect.php');
//Get the article title
function article_title ()
{
$getarticletitlequery = "select title from article where id='$id'";
$printtitle = mysql_query($getarticletitlequery);
$fetchtitle_tmp = @mysql_fetch_object($printtitle);
$fetchtitle = ucfirst(strtolower($data->$fetchtitle));
echo $fetchtitle ;
}
?>
[/php]
You forgot to use $variable-> (since you are using fetch_object).
or
[php]
<?
include('dbconnect.php');
//Get the article title
function article_title ()
{
$getarticletitlequery = "select title from article where id='$id'";
$printtitle = mysql_query($getarticletitlequery);
$fetchtitle = ucfirst(strtolower(mysql_result($printtitle,0,"title")));
echo $fetchtitle ;
}
?>
[/php]
<?
include('dbconnect.php');
//Get the article title
function article_title ()
{
$getarticletitlequery = "select title from article where id='$id'";
$printtitle = mysql_query($getarticletitlequery);
$fetchtitle_tmp = @mysql_fetch_object($printtitle);
$fetchtitle = ucfirst(strtolower($data->$fetchtitle));
echo $fetchtitle ;
}
?>
[/php]
You forgot to use $variable-> (since you are using fetch_object).
or
[php]
<?
include('dbconnect.php');
//Get the article title
function article_title ()
{
$getarticletitlequery = "select title from article where id='$id'";
$printtitle = mysql_query($getarticletitlequery);
$fetchtitle = ucfirst(strtolower(mysql_result($printtitle,0,"title")));
echo $fetchtitle ;
}
?>
[/php]
LOTRO Tips - Lord of the Rings Online Tips & Tricks
![]() |
•
•
•
•
•
•
•
•
DaniWeb PHP Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
•
•
•
•
access activation api blog blogger blogging blogs code combo competition dani daniweb data debugging development dreamweaver dropdownlist gdata gentoo google gpl html innovation key linux microsoft module net news openbsd php product programming reuse rss security serial source spam tags vista web wysiwyg xml
- I Need Help Please. Adding PHP Code To My Site. (PHP)
- How to test PHP code in offline in Linux + Apache 2 (PHP)
- PHP code not blending with HTML (PHP)
- My embedded php code won't execute (PHP)
- help executing a .wav file with php code (PHP)
Other Threads in the PHP Forum
- Previous Thread: Problem with displaying data..
- Next Thread: How to manipulate PHP date?


Linear Mode