473,698 Members | 2,241 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Missing element in array?!

I have the following query I run to pull some data from the db. The
sql (when run on the db) returns 2 elements. However, if I var dump my
variable ($aidlook) then the first element in the array does not show
up.

$getaid = mysql_query("SE LECT a_uid FROM `answers` WHERE `qid` =
$qid", $db);
$aidlook = mysql_fetch_arr ay($getaid,MYSQ L_NUM);

Doing a var dump returns: array(1) { [0]= string(1) "4" }

I should be getting 2 elements (4 and 5).

I am totally baffled. code as follows:

*************** ******
if (!is_array($aid look)) $aidlook = array($aidlook) ; // Check for the
existence of the array in case of null returns

if (!in_array($use rid,$aidlook)) // Look for our element which in
this case is "5"
{
if ($qstatus === 1) // Do a status check
{
}

answer_box($qid ,$answ); // additional function being run

} else
{
echo "Your Text Here";

}
}
../JLK

May 20 '07 #1
2 2787
>I have the following query I run to pull some data from the db. The
>sql (when run on the db) returns 2 elements. However, if I var dump my
variable ($aidlook) then the first element in the array does not show
up.

$getaid = mysql_query("SE LECT a_uid FROM `answers` WHERE `qid` =
$qid", $db);
$aidlook = mysql_fetch_arr ay($getaid,MYSQ L_NUM);

Doing a var dump returns: array(1) { [0]= string(1) "4" }

I should be getting 2 elements (4 and 5).
mysql_fetch_arr ay returns the results from ONE ROW. Since you are
only selecting one column in your query, you should have only one
element in the array. If you want the results from more than one
row, loop calling mysql_fetch_arr ay. Note that if you try doing
this and then merging the arrays, you're going to merge a whole
lot of arrays with a "0" index and likely you will end up with an
array with a single "0" index.

>I am totally baffled. code as follows:

************** *******
if (!is_array($aid look)) $aidlook = array($aidlook) ; // Check for the
existence of the array in case of null returns

if (!in_array($use rid,$aidlook)) // Look for our element which in
this case is "5"
{
if ($qstatus === 1) // Do a status check
{
}

answer_box($qi d,$answ); // additional function being run

} else
{
echo "Your Text Here";

}
}
./JLK

May 20 '07 #2
mysql_fetch_arr ay returns the results from ONE ROW. Since you are
only selecting one column in your query, you should have only one
element in the array. If you want the results from more than one
row, loop calling mysql_fetch_arr ay. Note that if you try doing
this and then merging the arrays, you're going to merge a whole
lot of arrays with a "0" index and likely you will end up with an
array with a single "0" index.
That I did not know..... Thank you.

../JLK

May 20 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
8329
by: maciej | last post by:
I got an array that consists of elements that are arrays also. Now I wish I could add an element to the middle of it. Let mi give you an example: array ( - array(1,15,apple), - array(2,28,banana), - array(3,41,orange) }
13
34380
by: Noah Spitzer-Williams | last post by:
Hello guys, I would like to do something seemingly simple: find out if an element in an array that is passed to my function exists. I used to think I could just do: if (arr) ... However, if this element's value happens to be 0, the conditional will return false, even though the element actually exists. Any ideas? Can you check if the element == null?
6
8339
by: David B. Bitton | last post by:
I am having a problem deserializing XML when the root node is missing a namespace declaration. My Type has an XmlTypeAttribute with a namespace defined. If I attempt to deserialize the XML, I get the dreaded <elementname xmlns=''> was not expected exception. If I comment out the XmlTypeAttribute, it works just fine. Just so you know, when I instantiate an instance of an XmlSerializer, I pass a default namespace to the ctor. ...
9
2312
by: Luke Wu | last post by:
Hello, I'm having some problems understanding 2 dimensional arrays. My problem relates to the following code: #include <stdio.h> #define M 3 #define N 3
9
11680
by: Harsha Srinath | last post by:
Athough this might not be directly relayed to C syntax, I thought some of you may find this an interesting problem :- 1.One number, in an array integers from 1 to 1,000,000 is present twice. How can you determine which one? Can you think of a way to do it using little extra memory? 2. How would you find the only missing element in that array? Can you think of a way to do it while iterating through the array only once. Is overflow a...
3
7303
by: Terry | last post by:
In the code below, I open a file using filestream, copy it to a byte array, and the write that array out to a new file. But when I check the size of the original file and the new file, the new file has one less byte than the original file (although the file itself still works fine). I was hoping someone could explain what is going on (why is there a byte missing, and what might that byte be). string originalFile =...
2
498
by: inventor | last post by:
I'm doing programming for my science prodject, and when I was programming (I'm building an alphebatizer) I ran into this bug: I've got an input box, but no button or output box. so I do some reaserch, insert a button, and when I open it up, instead of the button being added, I lost the input box. Can ANYONE PLEASE HELP ME!!!!!!!!!!!!! I've included a copy of my code as it is: <HTML> <HEAD> Riehl's Alphebatizer <SCRIPT...
11
1983
by: AB | last post by:
Hi All, I've got an array of objects, during the execution of the program I'd like to assign a particular object to a certain element in the object array. The sample code's like this... class ClassA { public: ClassA()
10
1884
by: ALKASER266 | last post by:
Hey guyz I have a prac and I am beginner and I did this code> Is my code is complete and if is it not complete how i can complete it? and how i can arrange it more? How I can make my driver to an array that generates an array of 20 students instead of my way of driver to enter it manually? THANK YOU VERY MUCH I will put the question then I will put my answer It is two codes one is Student which is the main one and the other one is...
0
8603
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9157
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
9026
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
8893
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
8861
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
6518
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
5860
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4619
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3045
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

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.