Go Back   vb.org Archive > vBulletin 4 Discussion > vB4 Programming Discussions
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools Display Modes
  #1  
Old 10-23-2011, 11:59 AM
Cory Megitt Cory Megitt is offline
 
Join Date: Aug 2011
Posts: 13
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default 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
Reply With Quote
  #2  
Old 10-23-2011, 12:32 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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.
Reply With Quote
  #3  
Old 10-23-2011, 12:45 PM
Cory Megitt Cory Megitt is offline
 
Join Date: Aug 2011
Posts: 13
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by kh99 View Post
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)
Reply With Quote
  #4  
Old 10-23-2011, 01:03 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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.
Reply With Quote
  #5  
Old 10-23-2011, 01:11 PM
setishock setishock is offline
 
Join Date: Feb 2008
Location: Houma, La.
Posts: 1,177
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Pardon my butting in but my curiosity is killing me. What would you use that for?
Reply With Quote
  #6  
Old 10-23-2011, 01:15 PM
Cory Megitt Cory Megitt is offline
 
Join Date: Aug 2011
Posts: 13
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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.
Reply With Quote
  #7  
Old 10-23-2011, 01:17 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by Cory Megitt View Post
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.
Reply With Quote
  #8  
Old 10-23-2011, 01:27 PM
Cory Megitt Cory Megitt is offline
 
Join Date: Aug 2011
Posts: 13
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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.
Reply With Quote
  #9  
Old 10-23-2011, 01:44 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Oh right. Sorry, change the echo line to

Code:
echo "$row[title]";
Reply With Quote
  #10  
Old 10-23-2011, 02:14 PM
Cory Megitt Cory Megitt is offline
 
Join Date: Aug 2011
Posts: 13
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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.
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 01:19 AM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2024, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.04295 seconds
  • Memory Usage 2,273KB
  • Queries Executed 13 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (1)ad_showthread_firstpost
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (3)bbcode_code
  • (4)bbcode_php
  • (2)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (1)pagenav_pagelink
  • (10)post_thanks_box
  • (10)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (10)post_thanks_postbit_info
  • (10)postbit
  • (10)postbit_onlinestatus
  • (10)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.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/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_postinfo_query
  • fetch_postinfo
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • pagenav_page
  • pagenav_complete
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete