Hi cragga_lfc,
Insert PHP is a closed system. Everything that it needs to work with must be in the code between the [insert_php] and [/insert_php] tags. See
http://www.willmaster.com/software/WPplugins/insert-php-wordpress-plugin-instructions.php#inandofitself
(Other information on that page may be useful.)
As an example, this section of your code
while($row = $result->fetch_assoc()) {
[/insert_php]
<tr>
<td>[insert_php] echo $row['Property Image'][/insert_php]</td>
<td>[insert_php] echo $row['Property Description'][/insert_php]</td>
<td>[insert_php] echo $row['Property Availability'][/insert_php]</td>
</tr>
[insert_php]
}
} else {
echo "0 results";
}
$conn->close();
[/insert_php]
doesn’t work because the second Insert PHP block doesn’t know what $row is. And the while loop is broken up.
For that particular section, this might work (untested, presented only as an example):
while($row = $result->fetch_assoc()) {
echo '<tr>';
echo '<td>';
echo $row['Property Image'];
echo '</td>';
echo '<td>';
echo $row['Property Description']
echo '</td>';
echo '<td>';
echo $row['Property Availability']
echo '</td>';
echo '</tr>';
}
} else {
echo "0 results";
}
$conn->close();
[/insert_php]
Will
Hi Will
thank you so much for helping me out i really appreciate it as i have been pulling my hair out for the last 3 days.
it has made changes to the errors now but no results still appear.
the error message i get now is:
Parse error: syntax error, unexpected ‘echo’ (T_ECHO), expecting ‘,’ or ‘;’ in /homepages/46/d567671028/htdocs/clickandbuilds/WordPress/LuxorEstates/wp-content/plugins/insert-php/insert_php.php(48) : eval()’d code on line 23
the displayed results are on:
http://luxor-lettings.com/results-2/
any help on this would be great. thank you
There’s an error on line 23 of the code between the [insert_php] and [/insert_php] tags.
See this page for more information about error messages:
http://www.willmaster.com/software/WPplugins/insert-php-wordpress-plugin-instructions.php#errormessages
And do read the rest of the page. It’s not an idle suggestion. It will help you.
Will
thank you Will
i have read the whole page and i think i have fixed the problem – however no parse issues appear
i get 0 results returned so it makes me think the script is wrong, but when i copy the script in phpMyAdmin it works
i dont know where to turn to now
the page – http://luxor-lettings.com/results-2/
here is my code:
<html>
<head>
<title>Available Properties</title>
</head>
<body>
<table>
<thead>
<tr>
<td>Property Image</td>
<td>Property Description</td>
<td>Property Availability</td>
</tr>
</thead>
<tbody>
[insert_php]
$servername = “db567706584.db.1and1.com”;
$username = “username”;
$password = “password”;
$dbname = “db567706584”;
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die(“Connection failed: ” . $conn->connect_error);
}
$sql = “SELECT Property Thumbnail URL,Property Title4HTML,Image Tag FROM Properties,Available WHERE Property Available Flag = Flag AND Property Available Flag = ‘2’”;
$result = $conn->query($sql);
if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
echo ‘<tr>’;
echo ‘<td>’;
echo $row[‘Property Image’];
echo ‘</td>’;
echo ‘<td>’;
echo $row[‘Property Description’];
echo ‘</td>’;
echo ‘<td>’;
echo $row[‘Property Availability’];
echo ‘</td>’;
echo ‘</tr>’;
}
} else {
echo “0 results”;
}
$conn->close();
[/insert_php]
</tbody>
</table>
</body>
</html>
any help Will would be greatly appreciated as i truly am thankful for your help so far as i feel i am so close
thank you
Hi Will
i fixed the 0 results as my SQL script was wrong – i amended it to the following which means the “0 results” no longer appears
SELECT Property Thumbnail URL,Property Title4HTML,Image Tag FROM Properties,Available WHERE Property Available Flag = Flag AND Property Available Flag = ‘2’
HOWEVER, i get no results showing now in a table
do you have any ideas?
thanks Craig
apologies the fields and tables are not showing with the “`” i added at the beginning and the end of each field
tried something different from my search on google:
// output data of each row
while($row = $result->fetch_assoc()) {
echo “<tr><td>” . $row[‘Property Image’] . “</td><td>” . $row[‘Property Description’] . “</td><td>” . $row[‘Property Availability’] . “</td></tr>”;
}
} else {
echo “0 results”;
}
$conn->close();
– but still no results show
Hi Will i did it!!!
I got data back into a table
i was “echoing” the field titles and not the fields from the db – dhuur!!
so i amend to:
while($row = $result->fetch_assoc()) {
echo “<tr><td>” . $row[‘Property Thumbnail URL’] . “</td><td>” . $row[‘Property Title4HTML’] . “</td><td>” . $row[‘Image Tag’] . “</td></tr>”;
}
now the results appear – but they don’t seem to be in a nice format – the text is aligned at the bottom
do you have any ideas how i can format this table now to look nice?!
thank you for your help was great to resolve it – just the formatting i can’t seem to figure out.
any ideas? would be greatly appreciated
i think i have resolved it
i needed to add
td {
vertical-align: top;
}
to the custom CSS plugin and the text when to the top
by all means tell me if this is wrong and wont work on other pages but it seems to have worked
beginners look if so
this is where i got the info:
http://stackoverflow.com/questions/2659508/html-align-table-rows-on-top
i think this is resolved – seems to have worked a treat on my pages adding the CSS
Thanks for noting your progress as you went along. And I’m glad it’s working for you.
Will