473,750 Members | 2,225 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

mysql_query(), mysql_numrows() , foreach() and implode() problems

13 New Member
OK, this is the relevant portion script:
[PHP]<?php





$username = '__'; // MySQL Database Username.
$password = '__'; // MySQL Database Password.
$server = '__'; // MySQL Database server (most likely localhost).
$db = '__'; // MySQL Database Name.
$num = 4; // Number of Wordpress Articles to show.
$tz = '__'; // Your Timezone written using the list at http://php.net/timezones


mysql_connect($ server,$usernam e,$password);
@mysql_select_d b("$db") or die('Unable to select database');


function GetWPData ($columnname, $limit) {
$q = mysql_query("SE LECT `post_date`, `post_title` FROM `wp_posts` WHERE (post_type = 'post' AND post_status = 'publish') ORDER BY `wp_posts`.`pos t_date` DESC LIMIT 0,$limit");
$num = mysql_numrows($ q);
$i=0;
while ($i < $num) {
$rows = mysql_result($q ,$i,"$columnnam e");
$array["$i"] = $rows;
$i++;
}
return $array;
}

function RearrangeDate ($var) {
$i=0;
foreach ($var as $td) {
$date = substr($td, 0, 10);
$y = substr($date, 0, 4);
$M = substr($date, 5, 2);
$d = substr($date, 8, 2);

$format = "$d/$M/$y";
// $d = day, $M = month, $y = year.

$array["$i"] = $format;
$i++;
}
return $array;
}

function RearrangeTime ($var) {
$i=0;
foreach ($var as $td) {
$time = substr($td, 11, 8);
$h = substr($time, 0, 2);
$m = substr($time, 3, 2);
$s = substr($time, 6, 2);

$format = "$h:$m";
// $h = hours, $m = minutes, $s = seconds.

$array["$i"] = $format;
$i++;
}
return $array;
}

function StringTogether ($d_arr, $t_arr, $title_arr) {
$i=0;
while ($i < $num) {
$d = $d_arr["$i"];
$t = $t_arr["$i"];
$title = $title_arr["$i"];

$format = "$d $t - $title";
// $d = date, $t = time, $title = title

$array["$i"] = $format;
$i++;
}
$text = implode('<br>', $array);
return $text;
}

mysql_close();

$p_d = RearrangeDate(G etWPData('post_ date',$num));
$p_t = RearrangeTime(G etWPData('post_ date',$num));
$p_title = GetWPData('post _title',$num);
$text = StringTogether( $p_d, $p_t, $p_title);

date_default_ti mezone_set("$tz ");
$lt = localtime(time( ), true);
$h = $localtime[tm_hour];
$m = $localtime[tm_min];
$s = $localtime[tm_sec];
$ld = date($ldformat) ;

$lt_format = "$h:$m"; // Local Time Format
// $h = hours, $m = minutes, $s = seconds.
$ld_format = "d/m/Y"; // Local Date Format
// d = days, m = months, Y = years.
$td_format = "$ld $lt"; // Time-Date Format
// $ld = date, $lt = time.

$td=$td_format;[/PHP]
when I run it I get the following errors:
Warning: mysql_query() [function.mysql-query]: Access denied for user '__'@'__' (using password: NO) in __ on line 20

Warning: mysql_query() [function.mysql-query]: A link to the server could not be __ on line 20

Warning: mysql_numrows() : supplied argument is not a valid MySQL result resource in __ on line 21

Warning: Invalid argument supplied for foreach() in __ on line 33

Warning: mysql_query() [function.mysql-query]: Access denied for user '__'@'__' (using password: NO) in __ on line 20

Warning: mysql_query() [function.mysql-query]: A link to the server could not be established in __ on line 20

Warning: mysql_numrows() : supplied argument is not a valid MySQL result resource in __ on line 21

Warning: Invalid argument supplied for foreach() in __ on line 50

Warning: mysql_query() [function.mysql-query]: Access denied for user '__'@'__' (using password: NO) in __ on line 20

Warning: mysql_query() [function.mysql-query]: A link to the server could not be established in __ on line 20

Warning: mysql_numrows() : supplied argument is not a valid MySQL result resource in __ on line 21

Warning: implode() [function.implod e]: Bad arguments. in __ on line 78
What needs fixing in my script to get everything working? The MySQL username and password were entered and correctly spelt despite what the error messages say and have only been removed for security reasons.

Can anyone help this newbie programmer?
Thanks :D
atyndall93
Oct 3 '07 #1
4 5153
atyndall
13 New Member
bump.
has anyone got an answer?
Oct 3 '07 #2
dafodil
392 Contributor
You cannot connect to the database if your password or username is wrong. Try to remove the password and see if you can get rid of the password error. In that way you'll see if there are any errors in your code.
Oct 3 '07 #3
atyndall
13 New Member
i can access mysql through phpmyadmin using th same user/pass combo I used in the script. I don't quite understand what you are trying to say.
Oct 4 '07 #4
dafodil
392 Contributor
Replace line 15 and 16 with this code:
Expand|Select|Wrap|Line Numbers
  1. $con = mysql_connect($server,$username,$password);
  2. mysql_select_db($db, $con);
  3.  
Don't forget the line 82:
Expand|Select|Wrap|Line Numbers
  1. mysql_close($con);
  2.  
Oct 5 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

5
3208
by: Andreas Paasch | last post by:
I'm having trouble with the implode function and need some help here. I've been reading at php.net but that didn't solve my problem. I'm having the below code: $query = "SELECT top1, top2, top3, top4, top5, top6, top7, top8, top9, pricesmall, pricelarge FROM esperia WHERE productnumber = '$bestil'";
4
15773
by: Bruce A. Julseth | last post by:
I know the following $sql will fail since there is no Customer='Smith'. I want to determine how to test a failure of mysql_query. I thought mysql_query returned false if a query failed. The test fail path is never taken in the following code is never taken. Also, I get an invalid argument on mysql_num_rows($Result) error message. $sql = "Update Table Set Password='password' where Customer='Smith';
6
5619
by: Rob | last post by:
hi, using PHP 4.3.3 and Apache (ADVX) 2.0.47 and i want to get the contents of my SETI stats site : $personal = implode("", @file("http://setiathome.ssl.berkeley.edu/fcgi-bin/fcgi?email=$email&cmd=user_stats_new")); which gives me this :
5
8780
by: lkrubner | last post by:
www.php.net says: >>>>>>>>>>>> Only for SELECT,SHOW,EXPLAIN or DESCRIBE statements mysql_query() returns a resource identifier or FALSE if the query was not executed correctly. For other type of SQL statements, mysql_query() returns TRUE on success and FALSE on error. A non-FALSE return value means that the query was legal and could be executed by the server. It does not indicate anything about the number of rows affected or returned. It...
2
2356
by: The.Relinator | last post by:
Hello, I am unable to get the following piece of code to work as desired. The fields valuable seems to contain all values however the vaules variable only contains the first assignied with $values = '\'' . $arry] . '\''; Any help regarding this issue would be kindly appreciated, thank you. $keys = array_keys($arry); $fields = '`' . $keys . '`'; $values = '\'' . $arry] . '\''; foreach($keys as $key)
18
5921
by: NoWhereMan | last post by:
Maybe a stupid question. ------------------------- 1 ------------------------- $str = ''; for($i=0; $i<10; $i++) $str .= $i;
1
2431
by: bronso | last post by:
I can`t get this block of code to work. I think there is something wrong with my syntax, but I can`t figure out what it is. source code look like this: $stemmer=array( array('stemme'=>'$ftenor', 'ref'=>'1.tenor', 'patch'=>'$ft'), array('stemme'=>'$atenor', 'ref'=>'2.tenor', 'patch'=>'$at'), array('stemme'=>'$fbass', 'ref'=>'1.bass'), 'patch'=>'$fb', array('stemme'=>'$abass', 'ref'=>'2.bass'),...
6
2435
by: tokcy | last post by:
Hi, I am having a problem with implode() function in PHP. whenever i am running my code it display an error like. Warning: implode() : Bad arguments. in D:\xampp\htdocs\admin\addspecs.php on line 8 and my code is $as = $_POST;
4
6339
by: mattehz | last post by:
Hey there, I am trying to upload old source files and came across these errors: Warning: Invalid argument supplied for foreach() in /home/mattehz/public_html/acssr/trunk/inc_html.php on line 59 Notice: Undefined index: args in /home/mattehz/public_html/acssr/trunk/inc_error.php on line 92 Warning: Invalid argument supplied for foreach() in /home/mattehz/public_html/acssr/trunk/inc_error.php on line 92
0
9577
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9396
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9339
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9256
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6804
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4887
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3322
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2804
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2225
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.