vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB4 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=252)
-   -   php script to extract thread titles (https://vborg.vbsupport.ru/showthread.php?t=272579)

Cory Megitt 10-23-2011 11:59 AM

php script to extract thread titles
 
I'm starting to program a php script to extract thread titles.
I am new to PHP but I'm learning ...

PHP Code:

<?php
$connect
=mysql_connect('localhost''root''xxxxx') or die(mysql_error());
echo 
"Connected to MySQL<br />";
mysql_select_db("vb") or die(mysql_error());
echo 
"Connected to Database";
$sql="SELECT 'title' FROM 'thread' WHERE 'dateline' BETWEEN 1315958401 AND 1318723199";
$result=mysql_query($sql);
while(
$row mysql_fetch_array($result))
{
      echo 
"$row <br />";
}  
?>

The output of this is:

Code:

Connected to MySQL
Connected to Database
Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in /Applications/XAMPP/xamppfiles/htdocs/mysql.php on line 8


kh99 10-23-2011 12:32 PM

I think the problem is the quotes you have around the column and table names. The quote character should be a backtick (`) and it looks like you have single quotes. (You don't really have to quote column and table names unless they have special characters).

Also, if you look at the page for mysql_query (http://us2.php.net/manual/en/function.mysql-query.php) under the Return Values section, you'll see that it can return FALSE if there's an error, so that's why your error message says that mysql_fetch_array() was expecting an array.

Cory Megitt 10-23-2011 12:45 PM

Quote:

Originally Posted by kh99 (Post 2260497)
I think the problem is the quotes you have around the column and table names. The quote character should be a backtick (`) and it looks like you have single quotes. (You don't really have to quote column and table names unless they have special characters).

Also, if you look at the page for mysql_query (http://us2.php.net/manual/en/function.mysql-query.php) under the Return Values section, you'll see that it can return FALSE if there's an error, so that's why your error message says that mysql_fetch_array() was expecting an array.

I've adjusted the line to read:
PHP Code:

$sql="SELECT `title` FROM `thread` WHERE `dateline` BETWEEN 1315958401 AND 1318723199"

I've adjusted the single quotes to backticks. I now have an output that looks like this:

Code:

Connected to MySQL
Connected to DatabaseArray
Array
Array
Array
Array
Array
Array
Array
Array
Array
.........  (it keeps on going for a little while)


kh99 10-23-2011 01:03 PM

That probably means it's working. The return from mysql_fetch_array() will be an array even if you are only selecting one column. So if you change your echo to $row['title'] you should see the titles.

setishock 10-23-2011 01:11 PM

Pardon my butting in but my curiosity is killing me. What would you use that for?

Cory Megitt 10-23-2011 01:15 PM

kh ... I get this now:
Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /Applications/XAMPP/xamppfiles/htdocs/mysql.php on line 10

setishock - The reason for this is to generate a report of thread titles from the 15th of each month to the 14th of each month.
Based on the data I have, it will populate an excel spreadsheet and make my monthly reporting for the manager a lot less time consuming.

It's only the start of what I want to have the script do.

kh99 10-23-2011 01:17 PM

Quote:

Originally Posted by Cory Megitt (Post 2260509)
kh ... I get this now:
Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /Applications/XAMPP/xamppfiles/htdocs/mysql.php on line 10


That usually means that quotes are mismatched or something.

Cory Megitt 10-23-2011 01:27 PM

PHP Code:

<?php
$connect
=mysql_connect('localhost''root''xxxx') or die(mysql_error());
echo 
"Connected to MySQL<br />";
mysql_select_db("vb") or die(mysql_error());
echo 
"Connected to Database";
$sql="SELECT `title` FROM `thread` WHERE `dateline` BETWEEN 1315958401 AND 1318723199";
$result=mysql_query($sql);
while(
$row mysql_fetch_array($result))
{
echo 
"$row['title']";
}  
?>

That's what it looks like -- and it appears to have proper quotes.

kh99 10-23-2011 01:44 PM

Oh right. Sorry, change the echo line to

Code:

echo "$row[title]";

Cory Megitt 10-23-2011 02:14 PM

PHP Code:

<?php
$connect
=mysql_connect('localhost''root''glide75') or die(mysql_error());
echo 
"Connected to MySQL<br />";
mysql_select_db("vb") or die(mysql_error());
echo 
"Connected to Database<br />";
$sql="SELECT `title` FROM `thread` WHERE `dateline` BETWEEN 1315958401 AND 1318723199";
$result=mysql_query($sql);
while(
$row mysql_fetch_array($result))
{
echo 
"$row[title]<br />";
}  
?>

This is the final and working script.

Thanks for the help kh99.
It worked.
Just need to figure out how to calculate the from date and to date properly as needed.


All times are GMT. The time now is 05:01 PM.

Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.01196 seconds
  • Memory Usage 1,756KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (3)bbcode_code_printable
  • (4)bbcode_php_printable
  • (2)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (1)pagenav_pagelink
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (10)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • printthread_start
  • pagenav_page
  • pagenav_complete
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete