4 Replies - 814 Views - Last Post: 21 September 2009 - 01:14 AM Rate Topic: -----

#1 hadi_php   User is offline

  • D.I.C Regular
  • member icon

Reputation: 10
  • View blog
  • Posts: 382
  • Joined: 23-August 08

show data with table prefix

Posted 20 September 2009 - 12:11 AM

 <?php
$result=mysql_query("SELECT * FROM latest");
while($row=mysql_fetch_object($result)) {
echo $row->name;
echo $row->title;
}
if (!$result)
  {
  die('Could not connect: ' . mysql_error());
  }
?>


it shows an error : Could not connect: Table 'forum.latest' doesn't exist

my db name : forum

When i imported 'latest' table then no prefix added even in latest it contains named as latest....

how do i fix it?

Is This A Good Question/Topic? 0
  • +

Replies To: show data with table prefix

#2 coolmac112   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 58
  • Joined: 30-August 09

Re: show data with table prefix

Posted 20 September 2009 - 01:38 AM

Can you provide a bit more code...i just need to see how you connected to the database.

You may also run the query directly from phpmyadmin, see if it really executes successfully.

if it does then you know it's your PHP code...It's important when debugging to break down the processes like that..makes getting to the problem a lot easier!
Was This Post Helpful? 0
  • +
  • -

#3 hadi_php   User is offline

  • D.I.C Regular
  • member icon

Reputation: 10
  • View blog
  • Posts: 382
  • Joined: 23-August 08

Re: show data with table prefix

Posted 20 September 2009 - 01:58 AM

<?php

$host	=	"my_db_host_name";
$dbuser	=	"username";
$dbpass	=	"********";
$db		="forum";

	$con = mysql_connect($host,$dbuser,$dbpass);
	if (!$con)
		  {
			  die('Could not connect: ' . mysql_error());
		  }
	$db_connect = mysql_select_db("$db");
	
	if (!$db_connect)
		{
			echo "Can Not Select The Database";
		}
?> 



I checked mysql connection it work well.....

And on my phpmyadmin i can run this query successfully

SELECT * FROM latest


Now what to do?
Why it trying to connect forum.latest .... i need to only connect to latest table...

forum.latest - where forum is my database name and may be it made a prefix with same as db name. But in phpmyadmin i can run all query without any prefix such as-

SELECT * FROM latest etc... if this query run on my sql server so why it doest running in a php page where mysql connection is ok.... why it output like this -

Could not connect: Table 'forum.latest' doesn't exist

i have no idea? need hand....please

This post has been edited by hadi_php: 20 September 2009 - 01:59 AM

Was This Post Helpful? 0
  • +
  • -

#4 coolmac112   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 58
  • Joined: 30-August 09

Re: show data with table prefix

Posted 20 September 2009 - 04:27 AM

This is going to sound a bit silly, maybe im wrong...but do this...restart your web server...get to phpmyadmin frontpage...don't select your database or anything then run your php script again...

I had a problem like this when I already had the database connection open in phpmyadmin, there's some clash that happens...i'm still researching this, btw...if this doesn't work...well i've tried!
Was This Post Helpful? 0
  • +
  • -

#5 coolmac112   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 58
  • Joined: 30-August 09

Re: show data with table prefix

Posted 21 September 2009 - 01:14 AM

How did that go? When you succeed please do update us, i am interested in knowing what the problem was and how it was overcome.

Thanks
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1