tags:

views:

485

answers:

7

Hello,

What is wrong with this code?

<?php

$link = mysql_connect('localhost', 'root', 'geheim');
if (!$link) {
    die('Could not connect: ' . mysql_error());
}
echo 'Connected successfully';
mysql_select_db("ebay");

$query = "SELECT * FROM Auctions";

$result = mysql_query($query) or die(mysql_error());


 $records = array();

 while($row = mysql_fetch_array($result, MYSQL_ASSOC))
 {
      $records[] = $row;
 }


foreach($records as $row) {
    echo "<table border=\"1\">";
    echo "<tr>";
    echo '<td><a href="view_record.php?num=' . {$row['ARTICLE_NO']} . {$row['ARTICLE_NAME']} . {$row['SUBTITLE']} . {$row['CURRENT_BID']} . {$row['START_PRICE']} . {$row['BID_COUNT']} . {$row['QUANT_TOTAL']} . {$row['QUANT_SOLD']} . {$row['STARTS']} . {$row['ENDS']} . {$row['ORIGIN_END']} . {$row['SELLER_ID']} . {$row['BEST_BIDDER_ID']} . {$row['FINISHED']} . {$row['WATCH']} . {$row['BUYITNOW_PRICE']} . {$row['PIC_URL']} . {$row['PRIVATE_AUCTION']} . {$row['AUCTION_TYPE']} . {$row['INSERT_DATE']} . {$row['UPDATE_DATE']} . {$row['CAT_1_ID']} . {$row['CAT_2_ID']} . {$row['ARTICLE_DESC']} . {$row['DESC_TEXTONLY']} . {$row['COUNTRYCODE']} . {$row['LOCATION']} . {$row['CONDITIONS']} . {$row['REVISED']} . {$row['PAYPAL_ACCEPT']} . {$row['PRE_TERMINATED']} . {$row['SHIPPING_TO']} . {$row['FEE_INSERTION']} . {$row['FEE_FINAL']} . {$row['FEE_LISTING']} . {$row['PIC_XXL']} . {$row['PIC_DIASHOW']} . {$row['PIC_COUNT']} . {$row['ITEM_SITE_ID']} . '</a></td>';  echo "<td>" . $row['SUBTITLE'] . "</td>";     echo "</tr>";
    echo "</table>";
}


mysql_close($link);

?>

I get unexpected { on line 27

edit: attached all code

+5  A: 

The {$variable} syntax is for use within strings, for example echo "This is my {$variable}";

Edit: What on earth is going on with this question?? (see edit history)

Greg
A: 

{fjdsakfjsal} only makes sense when inside a double quoted string.

Allain Lalonde
A: 

First format you code, like this for example:

foreach ($records as $row){ 
    echo ""; 
    echo ""; 
    echo ''; 
    echo "" . $row['SUBTITLE'] . ""; 
    echo ""; 
    echo ""; 
}

Always helpful when trying to figure out what is going wrong ;-)

Second, since you get an error on the opening bracket, the error lies there or in the code before. One more reason to format the code, so that you have a maximum of one bracket per line, so you know exactly which bracket confuses the php engine.

Third, I think RoBorg is right. You can output a variable as

"Somestring " . $some_variable

or as

"Somestring {$some_variable}"

Doing "Somestring" . {$some_variable} is incorrect.

Treb
A: 

RoBorg,

I seem to be using it that way, $row is a variable..

Joshxtothe4
No, you're using it outside a string. echo "hello {$var}" (correct) versus echo "hello " . $var (correct) versus echo "hello " . {$var} (wrong)
Greg
A: 

A word on SO usage: If you're considering posting a question, please Google for an answer first, and if none is found, think your question through thoroughly, anticipating what information we will need to answer your question so that there is no need to edit your question several times. If editing is necessary, use an addendum prefixed by "EDIT: " so that it's clear to all.

I've noticed that many of your questions would be better answered by a tutorial on MySQL and PHP syntax and usage.

Lucas Oman
A: 

Im pretty sure you do not need to have the curly braces around your variables and have them concatenated

try changing:
echo 'text' . {$row['COLUMN_ID'} . 'more text'
to
echo 'text' . $row['COLUMN_ID'] . 'more text'.

I think even echo 'text {$row['COLUMN_ID'} more text' will work as well.

Anders
A: 

It was working fine before however when I had just a few, the syntax was still the same {$row['name']]}

Lucas,

I did. My questions come from applying the tutorial.

Joshxtothe4
Joshxtothe4, please do not post replies to other peoples answer as an answer. This is not a discussion board.
Treb