473,396 Members | 1,865 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Query Function Array

73
Been using PHP for a little while now but have never really looked into using functions and such thinking I didn't really need them (coupled with me be lazy). I've started a new project and have decided to get a handle on them and this tutorial:

http://bytes.com/forum/thread632487.html

Has helped me quite a lot, I've made some modifications and it for the most part everything seems to be working however this one problem popping up is doing my head in I just can't seem to figure it out. I'm attempting to use the following function:

[PHP]
function query($qry)
{
if(!isset($this->database_link)) $this->connect();
$result = mysql_query($qry, $this->database_link) or die ("Error: ".mysql_error());
$returnArray = array();
$i = 0;
while ($row = mysql_fetch_array($result, MYSQL_BOTH));
if($row)
$returnArray[$i++] = $row;
mysql_free_result($result);
return $returnArray;
}
[/PHP]


I'm using the following code to access the function:
[PHP]
$parent_array = $db->query("SELECT * FROM table WHERE parent='Y' AND username='$username'");
[/PHP]

and I've tried echoing some results using the following:
[PHP]
echo $parent_array[1];
echo $parent_array['title'];
[/PHP]

But it is just showing up blank, probably somthing simple I'm missing but I've looked over that article many times and tried searching around but I'm coming up with nothing. I've narrowed down the problem as much as I can, I've tested other functions contained within the same file and they work fine, I've also tested the same query not using the function and arrays and it is also working.

Cheers for any help guys.
Jul 11 '08 #1
4 1186
pbmods
5,821 Expert 4TB
Heya, Jeigh.

Your script is probably generating an error. Enable debug messages to find out what's going on (http://bytes.com/forum/thread629295.html).
Jul 11 '08 #2
Jeigh
73
Thanks for that link, I was unaware you could turn Error Reporting on for just one page and with this new host I'm with (planning to switch to GoDaddy very soon) dosn't seem to allow me access to the php.ini file from the control panel. This helps a lot.

The error message I got was:

Notice: Undefined index: 1 in (address) on line 26

Line 26 being:

$title = $parent_array[1];

Never encountered this error before and couldn't manage to find any helpful information through google.

Thanks again.
Jul 12 '08 #3
pbmods
5,821 Expert 4TB
That just means that $parent_array[1] has no value. Probably means query() returned no results.

Try removing the semicolon from the end of your while loop in the query() method.

Incidentally, you can turn on error reporting in your .htaccess file (http://perishablepress.com/press/200...-via-htaccess/).
Jul 12 '08 #4
Jeigh
73
Always ends up being the simplest thing haha, I'm getting some results now. The script is still throwing up some wierd errors but through all my testing the codes become very messy so I assume I'll be able to sort all that out.

Thanks for all the help, I appreciate it.
Jul 12 '08 #5

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

Similar topics

2
by: lawrence | last post by:
A very strange bug. www.monkeyclaus.org is run by a cms I'm developing. One of types of users we allow is "justTestingTheSite", a type of user I developed to give demo's to prospective clients. The...
5
by: ensnare | last post by:
I'm attempting to create a threaded comment system involving PHP / MySQL. Currently, I have a table called comments which looks like: Table Comments: (comment_id, comment_root_id,...
9
by: Börni | last post by:
Hi, I have an sql query like this: SELECT column FROM table WHERE column1="3" AND column2="1" This query works perfectly if i run it in the command line, to be exactly it return two results. But...
6
by: frizzle | last post by:
Hi there I'm building this CMS, and at a point i have 3 similar drop downs. The values of the drop downs are called from a MysqlDB. The first one is just fine: do{ $selected = ($_GET ==...
8
by: Bill | last post by:
Hello out there; This may be a challenge but I'm certain it's possible but I can't seem to figure out how. I have a table that has several date fields, e.g., Date1, Date2, Date3, Date4 ......
13
by: Karl Groves | last post by:
I'm missing something very obvious, but it is getting late and I've stared at it too long. TIA for responses I am writing a basic function (listed at the bottom of this post) that returns...
2
by: mndprasad | last post by:
Hi friends, Am new to AJAX coding, In my program am going to have two texbox which going to implent AJAX from same table. One box is going to retrieve the value of other and vice...
5
by: KDawg44 | last post by:
Hi, Is there a way to get a multidimensional associative array with the entire result set? I would like to get a an array like this: resultsArray How can I accomplish this? Can I do...
4
by: zion4ever | last post by:
Hello good people, Please bear with me as this is my first post and I am relative new to ASP. I do have VB6 experience. I have a form which enables users within our company to do an intranet...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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,...
0
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...
0
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.