/    Sign up×
Community /Pin to ProfileBookmark

[RESOLVED] Parse Error :(

Parse error: syntax error, unexpected ‘{‘ in /home/bessent1/public_html/ben.broxie.co.uk/benwoolner/test.php on line 18

Thats the error message I’m getting running this code, i’m not 100% why though. I’ve check and all my brackets seem to be balanced and I can’t see a missing ;

The code I’m using i’ve used before too, on another website and I’ve had no issues with it, admitidly this is only has one query instead of the 2 of the orignal.

If I uncomment line 19 and comment all the if else statement it works and returns me the first set of data, but as I want an array that returns all the contents I was using the if else.

[code=php]
<?php

//connect to server and select database; you may need it
$mysqli = mysqli_connect(“localhost”, “xxx”, “xxx”, “bessent1_ben”);
// sets up queries
$get_data_qry = “SELECT * FROM portfolio_content”;

// sets up query calls
$get_data_res = mysqli_query($mysqli, $get_data_qry) or die(mysqli_error($mysqli));

//get and show 1st level navigation
if (mysqli_num_rows($get_data_res) < 1)
{
echo “<h3>We’re Sorry!</h3><p>We’ve searched our database and couldn’t find anything under that category</p>n”;
}
else ($data = mysqli_fetch_array($get_data_res))
{ //line 18
//$data = mysqli_fetch_array($get_data_res);
$title = ucwords(stripslashes($data[‘title’]));
$desc = $data[‘description’];
$thumb = $data[‘thumbnail’];
$stage = $data[‘main’];
$link = $data[‘link’];
}

echo $title.”<br />”;
include($desc);
echo “<br />”;
echo “<img src=”.$thumb.” /><br />”;
echo $stage.”<br />”;

if (is_null($link) == false)
{
echo $link.”<br />”;
}
?>
[/code]

Any help would be greatful

to post a comment
PHP

5 Comments(s)

Copy linkTweet thisAlerts:
@OctoberWindOct 10.2010 — Else is not a conditional check statement.

Remove this part of the Else line: ($data = mysqli_fetch_array($get_data_res))

You can then uncomment line 19, and your dataset should work.

The other option would be to convert it to:
[code=php]
elseif ($data = mysqli_fetch_array($get_data_res)) {
// then run your query
} else {
// numRows is less than 1, and mysql_fetch_array returns FALSE, so throw/catch your errors
}
[/code]


But that option is doing more work than you need to.
Copy linkTweet thisAlerts:
@lil_buggaauthorOct 10.2010 — Cheers for that OctoberRain. Now i'm having other issues, it does what I want it to do, kinda. I've tried to use the while loop and $display variable to display the content from the data base, which it does but not in a manor I can make sence of.

Here's the code[code=php]<?php

//connect to server and select database; you may need it
$mysqli = mysqli_connect("localhost", "xxx", "xxx", "bessent1_ben");
// sets up queries
$get_data_qry = "SELECT * FROM portfolio_content";


// sets up query calls
$get_data_res = mysqli_query($mysqli, $get_data_qry) or die(mysqli_error($mysqli));

//get and show 1st level navigation
if (mysqli_num_rows($get_data_res) < 1)
{
echo "<h3>We're Sorry!</h3><p>We've searched our database and couldn't find anything under that category</p>n";
}
else
{
while ($data = mysqli_fetch_array($get_data_res))
{
$title = ucwords(stripslashes($data['title']));
$desc = $data['description'];
$thumb = $data['thumbnail'];
$stage = $data['main'];
$link = $data['link'];


$display .= "<br /><br />" .$title."<br />";
display .= include($desc);
$display .= "<br />";
$display .= "<img src=".$thumb." /><br />";
$display .= $stage."<br />";

if (is_null($link) == false)
{
$display .= $link."<br /><br />";
}

echo $display;

}
}
?>[/code]


When I run that code it currently displays like so

Description 1

Title 1

Thumbnail 1

Stage 1

Link 1

Description 2

Title 1

Thumbnail 1

Stage 1

Link 1

Blank

Title 2

Thumbnail 2

Stage 2

Link 2

I had intended it to display the description after the title but it doesn't, and what's more confusing to me is the reason why it feels the need to duplicate the first lot of data underneath the description of the second.
Copy linkTweet thisAlerts:
@OctoberWindOct 10.2010 — what's up with this? missing the $, and what's the include doing there?
[code=php]display .= include($desc); [/code]

Furthermore, why are you building the $display variable inside the loop, then echoing it out right away? Just output the data. Also, by the looks of it, this could use some semantic markup as well.

[code=php]
echo "<table>";
while ($data = mysqli_fetch_array($get_data_res))
{
// this step is unnecessary
//$title = ucwords(stripslashes($data['title']));
//$desc = $data['description'];
//$thumb = $data['thumbnail'];
//$stage = $data['main'];
//$link = $data['link'];

echo "<tr><td>ucwords(stripslashes($data['title']));</td></tr>";
echo "<tr><td>$data['desc']</td></tr>";
echo "<tr><td><img src='$data['thumb']' /></td></tr>";
echo "<tr><td> $data['stage']</td></tr>";

if (!is_null($link))
{
echo "<tr><td><a href='$link'>$link</a></td></tr>";
}

}
echo "</table>";
[/code]
Copy linkTweet thisAlerts:
@lil_buggaauthorOct 10.2010 — I forgot to mention about that. I have the include because $desc only stores a link to an external file location, which contains the description.

I didn't want to overcroud the database with information so wanted to included it as a seperate file.

The database looks like this

id heading_id title description thumbnail main this is for the item on stage, either image or animation link


1 1 April Kelley http://www.ben.broxie.co.uk/benwoolner/portfolioit... http://www.ben.broxie.co.uk/benwoolner/images/port... http://www.aprilkelley.org.uk/

2 1 Little Shopper http://www.ben.broxie.co.uk/benwoolner/portfolioit... http://www.ben.broxie.co.uk/benwoolner/images/port...

some items within the table will contain links, others won't which is why I had the last if statement.
Copy linkTweet thisAlerts:
@lil_buggaauthorOct 12.2010 — anyone got any ideas?
×

Success!

Help @lil_bugga 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.18,
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,
)...