Jump to content

Still can't get the data pulled from MySQL field


sydewyndr

Recommended Posts

Using the following code, I'm able to pull in all of the data that exists in "post_title."  But I only need the newest one.

 

<?

$host='host'; 

$username='user';

$pass='pass';

$database='CTW_BM_db';

 

mysql_connect ($host, $username, $pass);

 

mysql_select_db($database) or die('Could not connect to the Database');

 

$info = mysql_query("SELECT post_title FROM wp_posts");

while ($r = mysql_fetch_array($info)) {

echo "<a href=the link>$r[post_title]<\/a>"; }

?>

 

 

Can someone please help me so it only displays the title stored in the newest record?

 

Also, I'm getting the following error messages at the top of my webpage:

Table 'CTW_BM_db.client_module_customization' doesn't exist

 

SELECT search, `replace` FROM client_module_customization WHERE client_module=50 AND active=1

 

And these error message at the bottom of my webpage:

Table 'CTW_BM_db.page_view' doesn't exist

 

SELECT ID FROM page_view WHERE month='2007-02' AND file_name='index' AND publication=5 AND client=1 AND source='module'

 

Table 'CTW_BM_db.page_view' doesn't exist

 

INSERT INTO page_view (month, file_name, publication, client, source, count) VALUES ('2007-02', 'index', 5, 1, 'module', 1)

Link to comment
Share on other sites

This looks like a problem with wordpress. (If that's what it is)

 

If you want the newest entry, it'd be something like SELECT post_title FROM wp_posts ORDER BY id DESC LIMIT 1

 

We'd need to know the fields in order to correctly specify the sorting.

Link to comment
Share on other sites

Ok, this is working great.  I have it pulling in the newest title, and it links to the webpage that I want it to.  But I'm still getting those messages at the top and bottom of the webpage.

 

Table 'CTW_BM_db.client_module_customization' doesn't exist

 

SELECT search, `replace` FROM client_module_customization WHERE client_module=50 AND active=1

 

And these error message at the bottom of my webpage:

Table 'CTW_BM_db.page_view' doesn't exist

 

SELECT ID FROM page_view WHERE month='2007-02' AND file_name='index' AND publication=5 AND client=1 AND source='module'

 

Table 'CTW_BM_db.page_view' doesn't exist

 

INSERT INTO page_view (month, file_name, publication, client, source, count) VALUES ('2007-02', 'index', 5, 1, 'module', 1)

 

I don't understand why they would show up.  Nowhere in my code am I looking for Table 'CTW_BM_db.client_module_customization' or the others it's referring to.

 

Does anybody have any idea why the code I put in above would cause these messages to appear?

Link to comment
Share on other sites

OK, I think I know what's causing the messages, but I'm not sure how to stop it.

 

The rest of the webpage uses a separate file called "db.php" to pull in all kinds of other data from 1 or more MySQL databases.  So the code I put in to pull this data in is conflicting with that, and trying to pull in tables that exist in the other database.

 

Is there a way I can have this code execute and connect to the database called "CTW_BM_db" but then disconnect so it doesn't try to use that code on the rest of the page?

Link to comment
Share on other sites

I'm not really sure where you meant for me to put that line of code, so I put it at the end.  So now my code looks like this:

 

<?php

 

$host='localhost';

$username='admin';

$pass='n3wsyst3m';

$database='CTW_BM_db';

 

mysql_connect ($host, $username, $pass);

 

mysql_select_db($database) or die('Could not connect to the Database');

 

$info = mysql_query("SELECT post_title FROM wp_posts ORDER BY ID DESC LIMIT 1");

while ($r = mysql_fetch_array($info))

{

echo "</a href=http://contentthatworks.com/hs_blog/wordpress target=_blank>$r[post_title]<//a>";

}

 

mysql_select_db();

?>

 

But I'm still getting the same messages at the top and bottom of my screen, and now I'm getting a new warning that shows up right below my output.  The output is correct and exactly what I want it to be by the way.

Warning: Wrong parameter count for mysql_select_db()

Link to comment
Share on other sites

Did you look up the function in the manual before using it?

mysql_select_db($database) or die('Could not connect to the Database');

 

You want to copy that only make it the other database, the one that has the tables the code is looking for.

Link to comment
Share on other sites

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.