Support Forums

Old 04-15-2006, 11:30 AM   #1
Don
Member
 
 
Join Date: Mar 2006
Location: United Kingdom
Posts: 89
Rep Power: 13
Don is on a distinguished road
Default Working on a Newsfeed

Hi everyone,

I am working on a newsfeed mod that will display (in ticker tape style) the contents of 'class_products/shortDescription' and 'class_products/price'. When user clicks on ticker tape scroller they will be taken to that listing (viewlisting.php).

Can someone check the following script for me, please.
Thanks

PHP Code:
<?php
// Connect To Database

$db "databasename";
$db_host "localhost";
$db_user "databaseusername";
$db_pass "databasepassword";
$con mysql_connect($db_host$db_user$db_pass)or die("Connect Error: ".mysql_error());
mysql_select_db($db$con);

// Start Building JavaScript

$out_js "feedno=newfeedtype('#000066',\"My Web Site\",\"http://www.mywebsite.com\");\n";

// MySQL Query

$result mysql_query("SELECT * FROM products ORDER BY datestamp DESC LIMIT 5");

// Build JavaScript for each item

while ($row mysql_fetch_object($result)) {
$this_date getdate();

$out_js .= "newstory(\"".$this_date['mday']."/".$this_date['mon']."/".$this_date['year']."\",\"viewlisting.php?id=".$row->id."\",\"".$row->shortDescription."\",\"".$row->price."\");\n";
}
// Close Connection To Database

mysql_free_result($result);
mysql_close($con);

// Send JavaScript

echo $out_js;
?>
__________________
Thanks,

Don.
Version 3.1 Developer

May God bless you in mighty ways.
Don is offline  
Old 04-15-2006, 12:26 PM   #2
Moderator
 
 
Join Date: Mar 2006
Posts: 3,927
Rep Power: 95
Lhotch is just really niceLhotch is just really nice
Default

At a glance it looks alright, id say go ahead and test it.

One thing I would recommend though is in the DB query, only select the fields you need. No sense grabbing all the fields if you only need a couple. Also I would recommend a "WHERE" clause so that it only grabs items that are set to display (ie they are authorized and not expired. Something like this...

SELECT shortDescription, dateadded, expiration, display FROM products WHERE expiration > NOW() AND display = 'Y' ORDER BY dateadded
__________________
Larry.
(Please note: I am not a 68C employee. I am a customer and volunteer who helps with questions where I can and the forums spam free)

Set your site apart from the competition with one of my modules......
Google Map Module | You Tube Module | Google Calendar Module | Event Calendar Module

68 Classifieds Important Links
Customer Area | Issue Tracker | Knowledge Base | User Manuals
Lhotch is offline  
Old 04-15-2006, 12:44 PM   #3
Don
Member
 
 
Join Date: Mar 2006
Location: United Kingdom
Posts: 89
Rep Power: 13
Don is on a distinguished road
Default

Thanks, Larry,

I can't get it to work and I think the fault is in this script rather than the .js it is feeding. The reason I asked you to take a look at it is because I don't understand PHP...this was put together after the old style of 'monkey see, monkey do'

Thanks,
Don.
__________________
Thanks,

Don.
Version 3.1 Developer

May God bless you in mighty ways.
Don is offline  
Old 04-15-2006, 01:02 PM   #4
Moderator
 
 
Join Date: Mar 2006
Posts: 3,927
Rep Power: 95
Lhotch is just really niceLhotch is just really nice
Default

What I would do is have the above code in its own php file. Then point a browser to it for debugging purposes.

Couple things, first move your date line above the loop, you dont need to do it every iteration of the loop since the result will all be the same day. Next if your looking to just get day/month/year I think your over complicating things all you need to do is this.

$this_date = date("d/m/Y");

In your while loop I would simple add an echo of $out_js to see if your query is returning anything. something like this...

PHP Code:
while ($row mysql_fetch_object($result)) {
$out_js .= "newstory(\"".$this_date."\",\"viewlisting.php?id=".$row->id."\",\"".$row->shortDescription."\",\"".$row->price."\");\n";
//for debugging
echo $out_js "<br />";
// end while loop 
On each iteration of the while loop you should see something printed on the screen.
__________________
Larry.
(Please note: I am not a 68C employee. I am a customer and volunteer who helps with questions where I can and the forums spam free)

Set your site apart from the competition with one of my modules......
Google Map Module | You Tube Module | Google Calendar Module | Event Calendar Module

68 Classifieds Important Links
Customer Area | Issue Tracker | Knowledge Base | User Manuals
Lhotch is offline  
Old 04-15-2006, 01:34 PM   #5
Don
Member
 
 
Join Date: Mar 2006
Location: United Kingdom
Posts: 89
Rep Power: 13
Don is on a distinguished road
Default

OK. I made a php file, pointed my browser at it and I got this:-

Warning: mysql_fetch_object(): supplied argument is not a valid MySQL result resource in /xxx/xxx/htdocs/newsfeed.php on line 22

Warning: mysql_free_result(): supplied argument is not a valid MySQL result resource in xxx/xxx/htdocs/newsfeed.php on line 33

I'm totaly in the dark here
__________________
Thanks,

Don.
Version 3.1 Developer

May God bless you in mighty ways.
Don is offline  
Old 04-15-2006, 03:03 PM   #6
Moderator
 
 
Join Date: Mar 2006
Posts: 3,927
Rep Power: 95
Lhotch is just really niceLhotch is just really nice
Default

Post the code you now have in your file so I can see what line the errors are referring to exactly.
__________________
Larry.
(Please note: I am not a 68C employee. I am a customer and volunteer who helps with questions where I can and the forums spam free)

Set your site apart from the competition with one of my modules......
Google Map Module | You Tube Module | Google Calendar Module | Event Calendar Module

68 Classifieds Important Links
Customer Area | Issue Tracker | Knowledge Base | User Manuals
Lhotch is offline  
Old 04-15-2006, 03:20 PM   #7
Don
Member
 
 
Join Date: Mar 2006
Location: United Kingdom
Posts: 89
Rep Power: 13
Don is on a distinguished road
Default

Thanks.
You will see that I have resorted to the original date method because I think it is to do with the way the .js deals with it.

newsfeed.php

<?php
// Connect To Database

$db = "XXX";
$db_host = "localhost";
$db_user = "XXX";
$db_pass = "XXX";
$con = mysql_connect($db_host, $db_user, $db_pass)or die("Connect Error: ".mysql_error());
mysql_select_db($db, $con);

// Start Building JavaScript

$out_js = "feedno=newfeedtype('#000066',\"ReTex International\",\"http://www.mysite.co.uk\");\n";

// MySQL Query

$result = mysql_query("SELECT * FROM products ORDER BY datestamp DESC LIMIT 10");

// Build JavaScript for each item

while ($row = mysql_fetch_object($result)) {
$out_js .= "newstory(\"".$this_date['mday']."/".$this_date['mon']."/".$this_date['year']."\",\"viewlisting.php?id=".$row->id."\",\"".$row->shortDescription."\",\"".$row->price."\");\n";
$this_date = getdate();
}

//while ($row = mysql_fetch_object($result)) {
//$out_js .= "newstory(\"".$this_date."\",\"viewlisting.php?id= " .$row->id."\",\"".$row->shortDescription."\",\"".$row->price."\");\n";
//for debugging
echo $out_js . "<br />";
// end while loop




// Close Connection To Database

mysql_free_result($result);
mysql_close($con);

// Send JavaScript

echo $out_js;
?>

Resulting in:-

Warning: mysql_fetch_object(): supplied argument is not a valid MySQL result resource in /usr/home/retex-international.co.uk/htdocs/newsfeed.php on line 21
feedno=newfeedtype('#000066',"ReTex International","http://www.retex-international.co.uk");

Warning: mysql_free_result(): supplied argument is not a valid MySQL result resource in /usr/home/retex-international.co.uk/htdocs/newsfeed.php on line 37
feedno=newfeedtype('#000066',"ReTex International","http://www.mysite.co.uk");

Thanks.
__________________
Thanks,

Don.
Version 3.1 Developer

May God bless you in mighty ways.

Last edited by Don; 04-16-2006 at 07:15 AM.
Don is offline  
Old 04-15-2006, 03:35 PM   #8
Moderator
 
 
Join Date: Mar 2006
Posts: 3,927
Rep Power: 95
Lhotch is just really niceLhotch is just really nice
Default

Don, you are getting the "supplied argument is not a valid MySQL result resource" error because your query is failing.

You query is.....

$result = mysql_query("SELECT * FROM products ORDER BY datestamp DESC LIMIT 10");

"products" is not a complete table name. When you did the installation I beleive there was a prompt for a table prefix which defaulted to class but you may have changed it. The actual table name should be "class_products" so your query should look like this...

$result = mysql_query("SELECT * FROM class_products ORDER BY datestamp DESC LIMIT 10");

Additionally you should put in some error checking so it looks like this....

PHP Code:
if(!$result mysql_query("SELECT * FROM class_products ORDER BY datestamp DESC LIMIT 10"){
      die(
'Invalid query: ' mysql_error());

__________________
Larry.
(Please note: I am not a 68C employee. I am a customer and volunteer who helps with questions where I can and the forums spam free)

Set your site apart from the competition with one of my modules......
Google Map Module | You Tube Module | Google Calendar Module | Event Calendar Module

68 Classifieds Important Links
Customer Area | Issue Tracker | Knowledge Base | User Manuals
Lhotch is offline  
Old 04-15-2006, 03:47 PM   #9
Don
Member
 
 
Join Date: Mar 2006
Location: United Kingdom
Posts: 89
Rep Power: 13
Don is on a distinguished road
Default

I now get:-
Parse error: parse error, unexpected T_EXIT in /usr/home/retex-international.co.uk/htdocs/newsfeed.php on line 17

Line 17 =
PHP Code:
die('Invalid query: ' mysql_error()); 
__________________
Thanks,

Don.
Version 3.1 Developer

May God bless you in mighty ways.
Don is offline  
Old 04-15-2006, 03:50 PM   #10
Moderator
 
 
Join Date: Mar 2006
Posts: 3,927
Rep Power: 95
Lhotch is just really niceLhotch is just really nice
Default

Quote:
Originally Posted by Don
I now get:-
Parse error: parse error, unexpected T_EXIT in /usr/home/retex-international.co.uk/htdocs/newsfeed.php on line 17

Line 17 =
PHP Code:
die('Invalid query: ' mysql_error()); 
Do you have the curly brace at the end of the qury line and then the closing curly brace after the "die" statement?
__________________
Larry.
(Please note: I am not a 68C employee. I am a customer and volunteer who helps with questions where I can and the forums spam free)

Set your site apart from the competition with one of my modules......
Google Map Module | You Tube Module | Google Calendar Module | Event Calendar Module

68 Classifieds Important Links
Customer Area | Issue Tracker | Knowledge Base | User Manuals
Lhotch is offline  
 

Bookmarks

Thread Tools
Display Modes

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
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
page 2 of 2 not working GSP v3.1 Questions & Support 10 03-02-2007 07:00 PM
Links Not Working Scooter v3.1 Questions & Support 6 11-13-2006 10:36 PM
Working with the psd file GSP v3.1 Modules & Modifications 2 09-30-2006 06:19 AM
Searching by join date not working? civ v3.1 Questions & Support 2 07-27-2006 09:00 AM
Contact us,Owner, New registration mail not working!! garysr v3.1 Questions & Support 12 06-09-2006 04:44 PM


All times are GMT -4. The time now is 02:14 AM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0