/    Sign up×
Community /Pin to ProfileBookmark

Array Outputting

Here’s my problem my script works so far untill it trys to output an array then it just stops and shows nothing.

[code=php]

$action = $_GET[‘action’];
echo “Photo editing is undermantinace please check back later”;
$albumSql = “SELECT * FROM `PhotoAlbums` WHERE `ID` = ‘$user_id’ AND `AlbumID` = ‘$action'”;
$albumResults = mysql_query($albumSql,$conn);
$array = mysql_fetch_array($albumResults);
echo”<form method =’post’> Form Here $action $array</form>”;
[/code]

this works fine but once i add this line of code

[code=php]print_r($array);[/code]

then it just stops working and nothing is echoed before it
and i don’t know why.

to post a comment
PHP

4 Comments(s)

Copy linkTweet thisAlerts:
@DasherDec 06.2010 — Try enabling error reporting
[code=php]
error_reporting(E_ALL);
[/code]


I don't think you can just echo an array. So your lines

[code=php]$array = mysql_fetch_array($albumResults);
echo"<form method ='post'> Form Here $action $array</form>"; [/code]


Likely have errors too.

Rename $array (reserved word?) $a_row


[code=php]
while ($a_row= mysql_fetch_array($albumResults)){

echo $a_row[0]."&nbsp;".$a_row[1]."&nbsp;".$a_row[2]."<br>";
// etc... $a_row[n] where n = number of fields -1 returned per query row.
}[/code]
Copy linkTweet thisAlerts:
@NogDogDec 06.2010 — It's OK to name a variable $array, though not very good practice since it conveys absolutely no meaning (well, other than that it's supposedly an array ? ). If you're just looking for a quick and dirty way of outputting an array, print_r() will work, but if you are echoing it you should add the 2nd optional argument with a true value.
[code=php]
echo "blah blah" . print_r($array, 1) . "yadda yadda";
[/code]

If you just want the values, you can implode() the array:
[code=php]
echo "<h2>Here it is:</h2><p>" . implode("<br />n", $array) . "</p>n";
[/code]

If you need the keys, too, foreach() can be your friend:
[code=php]
echo "<ul>n";
foreach($array as $key => $value) {
echo "<li><strong>$key:</strong> $value</li>n";
}
echo "</ul>n";
[/code]
Copy linkTweet thisAlerts:
@YokiestauthorDec 06.2010 — I've dont the error_reporting(E_ALL); and i get nothing also when i just echo $array it echos "Array" meaning it is creating an array when it fetches it from the database however when i try to display any information from the database the whole script stops working.

i took out everything and just had it echo out text and it did that fine however when i had it echo out a simple mysql statement it just stop working.

alos another thing i found out is if i remove $action from the mysql statement it works
Copy linkTweet thisAlerts:
@NogDogDec 06.2010 — Along with the error_reporting, add this line at the top:
[code=php]
ini_set('display_errors', 1);
[/code]

Note, however, that if display_errors is turned off in you server's settings, parse errors will not get displayed (since the ini_set() would then never get executed).
×

Success!

Help @Yokiest spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.7,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...