0

Here's the PHP and I'll explain as I go

$query = "SELECT id, attendees FROM events WHERE creator = '63' AND attendees LIKE '%74%'";

$result = mysqli_query($dbc,$query);

$uid_events = mysqli_fetch_array($result,MYSQLI_ASSOC);

echo $_GET['callback'] . '("' . stripslashes(json_encode($uid_events)) . '");';

It's a jquery JSONP request and I'm trying to retrieve 2 records.

When I test this exact same query directly in my database I get these 2 records:

34acb43ccc4c34b911ba8b7d850a846b63 - 63,1,74     
09fa87b2ed809d6741c43dd669c83e1a63 - 63,74

But the PHP echoes out:

({"id":"34acb43ccc4c34b911ba8b7d850a846b63","attendees":"63,1,74"}");

Any help would be appreciated.

0

3 Answers 3

2

try this:

while ($uid_events = mysqli_fetch_array($result,MYSQLI_ASSOC)) {
   echo $_GET['callback'] . '("' . stripslashes(json_encode($uid_events)) . '");';
}
Sign up to request clarification or add additional context in comments.

5 Comments

The only thing I'm wondering is if the echo'd line would stay the same.
no, $uid_events will change during the while loop, it will contain an array with data of every line from your select query. sorry for my bad english :)
@Alon - I'm just saying, look at the output (in the question) and imagine what the code is doing on the client. I'm not entirely sure, but it looks like that output would not be useful two or more lines in a row.
@JaredFarrish - I agree with you, he should manipulate the results from the query, and output in the while loop only the data from the db.
Actually all the scripting that had to be done was in the PHP script. I just used the output to help me debug
1

The function mysqli_fetch_array fetches only one row (or returns FALSE if there are no more rows). If you want to read all rows you should run this statement in a loop, until it returns FALSE.

Comments

1

mysqli_featch_array() returns a single row, then advances the cursor to the next row. To get all rows, you need to call it in a loop.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.