mayiek
Forum Replies Created
-
Forum: Plugins
In reply to: Retrieving data from an external mysql databaseFinally I made it.
Just to make everyone know (who might be searching for the same thing):
$quoteName=single_post_title('',false); $myshops = $wpdbtest_otherdb->get_results("SELECT * FROM shops WHERE shopName='$quoteName'"); foreach ($myshops as $myshop) {echo $myshop->shopName,' ', $myshop->shopEmail;} ?> </p>The whole thing was that
$quoteName=single_post_title('',false);I am very very happy 🙂
Do I need to enter `$wpdbtest_otherdb = new wpdb(‘username’, ‘password’, ‘shops’, ‘websitesql.whatever.com’);
$wpdbtest_otherdb->show_errors();`
in every post’s html code, or could I do it only once for all posts?Forum: Plugins
In reply to: Retrieving data from an external mysql databaseAs I know nothing about The Loop, I read that single_post_title(); works out of it. I tried that:
$quoteName=single_post_title(); $myshops = $wpdbtest_otherdb->get_results("SELECT * FROM shops WHERE shopName='$quoteName'"); foreach ($myshops as $myshop) {echo $myshop->shopName,' ', $myshop->shopEmail;} ?> </p>but I am getting an empty page 🙂
I have tried get_the_title(); , the_title();, single_post_title();, $post->post_title, but none of them seems to work. I believe this is a variable to variable mapping issue.
Forum: Plugins
In reply to: Retrieving data from an external mysql database$myshops = $wpdbtest_otherdb->get_results("SELECT * FROM shops WHERE shopName=wp_title()");I suppose I cannot use something like that… I get a message : Fatal error: Can’t use function return value in write context in…..
How can I pass the return value of wp_title() to the sql quote? The value of the shopName is an varchar(50)…
Forum: Plugins
In reply to: Retrieving data from an external mysql databaseI am very happy to announce that it worked ! I am amazed !
A huge “thank you” to Michael !
Finally I got the one with the external db to work… no need to use the same db with wordpress. Now the thing is, how do I map the post title (name of the shop in wp) to the database variable (name of the shop in sql db) to start retrieving data.the function for the retrieving of data must be used about 30 times. What should I use?
$myshops = $wpdbtest_otherdb->get_results("SELECT * FROM shops"); foreach ($myshops as $myshop) { echo $myshop->shopName . '<br />';where “echo $myshop->VariableFromTable . ‘
‘;” ??Thanks
Forum: Plugins
In reply to: Retrieving data from an external mysql databaseHi Michael,
I have already read that post and I was getting this error:
Warning: Invalid argument supplied for foreach() in /hermes/bosweb/web272/b2727/website_here/wordpress/wp-content/plugins/exec-php/includes/runtime.php(42) : eval()’d code on line 4
I pasted this code in a post (using php-exec):
<?php $wpdbtest_otherdb = new wpdb('username', 'password', 'shops', 'websitesql.whatever.com'); $wpdbtest_otherdb->show_errors(); $myshops = $wpdbtest_otherdb->get_results("SELECT * FROM shops"); foreach ($myshops as $myshop) {echo $myshop->shopName, '<br />'; } ?>and that’s when I decided to start a new thread 🙂
the reason for the SELECT * quote is just to test if this works. I know much about c++ programming but I’m a newbie in php so I don’t know 100% of what happens in the code.
Thanks for your reply