This is the community forum. For a developer response use the Client Area.
Follow us on Facebook, Twitter and YouTube!

how to a access tables
#1

Hi
I want to get the custom_id from the pages table and display it what is a good way of doing this.
Thanks
Peter
Reply
#2

Hi
Here is code I am using
<?php
define ('IN_COMMENTICS', '1');
require "../comments/includes/db/connect.php";

$query = mysql_query("SELECT * FROM `".$mysql_table_prefix."pages'");
if(!$con){
die('could not connect:' .mysql_error());
}
mysql_select_db("pages", $con);

$result = mysql_query("SELECT * FROM `".$mysql_table_prefix."pages'");
echo"<table border ='1'>
<tr>
<th>Custom ID</th>
</tr>";

While($row = my_sql_fetch_array($result)){
echo"<tr>";
echo"<td>". $row['custo_id]."</td>";
echo"</tr>";
}
echo"</table>";

?>
And error on page says could not connect Table a7...._comment.pages doesn't exist
Any help appreciated
Thanks
Peter
Reply
#3

Hi
When I am logged into my database on my server When I run
SELECT * FROM `pages` on sql query all is displayed as should be.
I just get could not connect error when i try to run it from my page .
help welcome
Thanks
Peter
Reply
#4

The problem with your code is that it has a ' character instead of a ` character in the query, so "SELECT * FROM `".$mysql_table_prefix."pages'"
should be
PHP Code:
<?php 
"SELECT * FROM `".$mysql_table_prefix."pages`"
and $row['custo_id'] should be $row['custom_id']

Also, do you only need a custom id of a specific page, or do you need all of the custom ids?

I'm giving you three guesses...
Reply
#5

Hello Static,
it is to get just one entry the ("SELECT id FROM pages WHERE custom_id = 'cagarole'") and only list first occurrence.
(as cagarole is the page name 'cmtx_title' which I know without actually opening my database)
which I then want to use in this query Like:


$query = mysql_query("SELECT MAX(rating) AS highest_rating FROM comments WHERE is_approved = '1' AND page_id = '("SELECT id FROM pages WHERE custom_id = 'cagarole'")'");
$result = mysql_fetch_assoc($query);
$highest_rating = $result["highest_rating"];

Otherwise I have to hardcode both queries.
Other question can I run query's on two tables at the same time.
Thanks for your help with this.
Peter




Reply
#6

Hi Static,
here is my new code:
<?php
define ('IN_COMMENTICS', '1');
require "../comments/includes/db/connect.php";

$query = mysql_query("SELECT `id` FROM `".$mysql_table_prefix."pages` WHERE custom_id = `cagarole` LIMIT 1" );
if(!$con){
die('could not connect:' .mysql_error());
}
mysql_select_db("pages", $con);

$result = mysql_query("SELECT `id` FROM `".$mysql_table_prefix."pages`" WHERE custom_id = `cagarole` LIMIT 1");
echo"<table border ='1'>
<tr>
<th> ID</th>
</tr>";

While($row = my_sql_fetch_array($result)){
echo"<tr>";
echo"<td>". $row['id']."</td>";
echo"</tr>";
}
echo"</table>";

?>
But I still get "could not connect" error.
Thanks for your help.
Peter
Reply
#7

Try this:

PHP Code:
<?php
define
('IN_COMMENTICS', '1');
require
"../comments/includes/db/connect.php";

$query = mysql_query("SELECT id FROM `".$mysql_table_prefix."pages` WHERE custom_id = 'cagarole'");
$result = mysql_fetch_assoc($query);
$id = $result["id"];

$query = mysql_query("SELECT MAX(rating) AS highest_rating FROM `".$mysql_table_prefix."comments` WHERE is_approved = '1' AND page_id = '$id'");
$result = mysql_fetch_assoc($query);
$highest_rating = $result["highest_rating"];
?>

Have you completed the interview?
Reply
#8

Thanks Steven,
that is exactly what I wanted. As I know the names of all my pages this makes things a lot easier.
Peter
Reply


Possibly Related Threads…
Thread / Author Replies Views Last Post

Forum Jump:


Users browsing this thread: 1 Guest(s)