Whats wrong with my link? - php

I am trying to echo a array value in a link, but it is coming up in dreamweaver as an error, but I cant work out what I have done wrong, can anyone tell me what is wrong with this line please ?.
thanks :-)
echo '';
EDIT >>>>>>>>>>>>>>>>>>>>>>>>
THIS IS THE FULL CODE :
$result = mysql_query("SELECT * FROM hqfjt_chronoforms_data_addemailtemplate");
while ($row = mysql_fetch_object($result)) {
echo '<div class="namerow">';
echo '<th>';
echo $row->emailformname;
echo '</th>';
echo '</div>';
echo '<div class="messagerow">';
echo '<th>';
echo $row->emailformmessage;
echo 'dssd';
echo '<tr></tr>';
echo '</div>';
}
echo '</th>';
mysql_free_result($result);
If I echo the cf_uid
echo $row->cf_uid;
this works fine and displays the unique id for each record next to it in the table, I just need to take that id thats is being echo'd and put in at the end of the link so that it looks like http://link&token=2626382837728 << (cf_uid)
FIXED !
Thanks for everyone's help on this work, I worked out what was wrong in the end, what I thought was an array didn't appear to be, this code worked in the end >>
$result = mysql_query("SELECT * FROM hqfjt_chronoforms_data_addemailtemplate");
while ($row = mysql_fetch_object($result)) {
echo '<div class="namerow">';
echo '<th>';
echo $row->emailformname;
echo '</th>';
echo '</div>';
echo '<div class="messagerow">';
echo '<th>';
echo $row->emailformmessage;
$id = $row->cf_uid;
echo 'LINK';
echo '<tr></tr>';
echo '</div>';
}
echo '</th>';
mysql_free_result($result);

Try to separate the strings and the variables.
echo '';
update: If you get an error in this line the problem could be the line before!

alternatively you can try this
echo '';
This way you can just concat the string

echo "SOME NAME FOR THE LINK";
[edit based on updated post]
Use this:
echo 'dssd';
However, I must ask... is there an array variable $detail which has a key 'cf_uid'? And what syntax error are you getting (after you tried this)?
[edit based on comment]
Since it's $row and since it's an object:
echo 'dssd';

Related

JSON TO HTML ROW USING PHP

I need to convert JSON into a list using PHP, Tried code below but cannot make it work
$json=file_get_contents("http://feeds.mse.mk/service/FreeMSEFeeds.svc/ticker/JSON/8BA941D0-D6E6-44BD-8D8B-47FDB7A563FA");
$data = json_decode($json);
if (count($data->stand)) {
// Open the table
echo "<table>";
// Cycle through the array
foreach ($data->stand as $idx => $stand) {
// Output a row
echo "<tr>";
echo "<td>$stand->AvgPrice</td>";
echo "<td>$stand->Description </td>";
echo "</tr>";
}
// Close the table
echo "</table>";
}
And I want to show list as here (not as a table):
http://prntscr.com/no1479
your all code is right but you can use stand class that is wrong your class is GetTickerJSONResult and so change the class stand to GetTickerJSONResult.
try this modified code..
<?PHP
$set =json_decode($json);
if (count($set->GetTickerJSONResult)) {
echo "<table>";
foreach ($set->GetTickerJSONResult as $idx => $stand) {
echo "<tr>";
echo "<td>$stand->AvgPrice</td>";
echo "<td>$stand->Description </td>";
echo "</tr>";
}
echo "</table>";
}
?>
It does not work because in $data->stand there is nothing.

echo loop inside html tags

I'm trying to echo a loop inside another loop inside html tags anyone can help pls ?
i know theres a parse error but can someone help me figure it out,
also another problem that when i run inside the loop
$row['Rating']
i get the data from the database but if i put it before in a variable
$stars = $row['Rating'];
it does not give any value anyone ??
<?php
echo '<td>' .
for($x=1;$x<=$stars;$x++) {
echo '<img src="images/empty-star.png" />';
}
if (strpos($stars,'.')) {
echo '<img src="images/full-star.png" />';
$x++;
}
while ($x<=5) {
echo '<img src="path/to/blank/star.png" />';
$x++;
}
. '</td>';
?>
thank you in advance
<?php
echo '<td>';
for($x=1;$x<=$stars;$x++) {
echo '<img src="images/empty-star.png" />';
}
if (strpos($stars,'.')) {
echo '<img src="images/full-star.png" />';
$x++;
}
while ($x<=5) {
echo '<img src="path/to/blank/star.png" />';
$x++;
}
echo '</td>';
?>
as for your $row question, it seem unrelated to the code you supplied. And no, values cannot disappear when assigned.

using file() and preg_split() to create a table

let's say if I have a txt file and inside has info sample like this:
amy,anderson,aldergrove,archery,anchovies,110
bill,bonds,burnaby,bowling,beer,100
cameron,carson,cameroon,cars,candy,120
henry,henderson,harrison,helping,hamburgers,90
dorothy,dust,denmark,driving,drinks,80
ed,edmunson,edmonton,eating,eggs,77
fred,fredrickson,fernie,flying,fries,140
and I want to use the file() and preg_split() function to call it out and show as a table what's the easiest way to do it?
I know how to call it out using file() function but I'm not sure how to replace the , and make it look like a table.
http://et4891.site90.com/sample.jpg <---this is a sample of how I want it to look like.
Below is what I did to call out the txt file.
<?php
$fileContentsArray = file("aaa.txt");
echo "<table>";
foreach($fileContentsArray as $one_persons_data)
{
echo "<tr>$one_persons_data</tr>";
}
echo "</table>"
?>
how should I modify this to make it look like the image I posted?
Thanks in adavance....
Is preg_split required? Better to use explode in this case. Anyway:
<?php
$fileContentsArray = file("aaa.txt");
echo "<table>";
foreach($fileContentsArray as $one_persons_data)
{
echo '<tr>';
$splitted = preg_split('/,/', $one_persons_data);
foreach ($splitted as $one) {
echo "<td>$one</td>";
}
echo '</tr>';
}
echo "</table>"
You can do this:
<?php
$rows = file('data.txt');
echo '<table>';
foreach($rows as $row){
echo '<tr>';
foreach(explode(',',$row) as $field){
echo '<td>';
echo htnlentities($field);
echo '</td>';
}
echo '</tr>';
}
echo '</table>';
Hope this can help you.

Echo selective data (rows) from multidimensional array in PHP

I have an array coming from a .csv file. These are coming from a real estate program. In the second column I have the words For Sale and in the third column the words For Rent that are indicated only on the rows that are concerned. Otherwise the cell is empty. I want to display a list rows only For Sale for example. Of course then if the user clicks on a link in one of the rows, the appropriate page will be displayed.
I can't seem to target the text in the column, and I can't permit that the words For Sale be used throughout the entire array because they could appear in another column (description for example).
I have tried this, but to no avail.
/* The array is $arrCSV */
foreach($arrCSV as $book) {
if($book[1] === For Sale) {
echo '<div>';
}
echo '<div>';
echo $book[0]. '<br>';
echo $book[1]. '<br>';
echo $book[2]. '<br>';
echo $book[3]. '<br>';
echo $book[6]. '<br><br><br>';
echo '</div>';
}
I also tried this:
foreach($arrCSV as $key => $book) {
if($book['1'] == 'For Sale') {
echo '<div>';
}
echo '<div>';
echo $book[0]. '<br>';
echo $book[1]. '<br>';
echo $book[2]. '<br>';
echo $book[3]. '<br>';
echo $book[6]. '<br><br><br>';
echo '</div>';
}
Do you mean:
foreach($arrCSV as $key => $book) {
if($book['1'] == 'For Sale') {
echo '<div></div>';
}else{
echo '<div>';
echo $book[0]. '<br>';
echo $book[1]. '<br>';
echo $book[2]. '<br>';
echo $book[3]. '<br>';
echo $book[6]. '<br><br><br>';
echo '</div>';
}
}
I found a solution here:
PHP: Taking Array (CSV) And Intelligently Returning Information
$searchCity = 'For Sale'; //or whatever you are looking for
$file = file_get_contents('annonces.csv');
$results = array();
$lines = explode("\n",$file);
//use any line delim as the 1st param,
//im deciding on \n but idk how your file is encoded
foreach($lines as $line){
//split the line
$col = explode(";",$line);
//and you know city is the 3rd element
if(trim($col[1]) == $searchCity){
$results[] = $col;
}
}
And then:
foreach($results as $Rockband)
{
echo "<tr>";
foreach($Rockband as $item)
{
echo "<td>$item</td>";
}
echo "</tr>";
}
As you can see I'm learning. It turns out that by formulating a question, a series of similar posts are displayed, which is much quicker and easier than using google. Thanks.

$string is not showing up in php search

Just got some help with my ajax/php search but now my issue is that the link is not even showing up on the search page. The echo results are showing up but the $string isn't.
Thanks for the help.
//echo $query;
$result = mysqli_query($link, $query);
$string = '';
if($result){
if(mysqli_affected_rows($link)!=0){
while($row = mysqli_fetch_array($result,MYSQLI_ASSOC)) {
echo '<p> <b>'.$row['title'].'</b> '.$row['post_ID'].'</p>' ;
$string .= "<p><a href='set-detail.php?recordID=".$row['post_ID']."'>".$row['title']."</a></p>";
}
} else {
echo 'No Results for :"'.$_GET['keyword'].'"';
}
I don't see where you echo $string. If you put the echo command in there for $string it may begin to work.
You're not printing $string anywhere.
Are you sure you meant to use $string, and not just echo it, like you have with the line above?
You need to include echo $string; or simple echo the line as it is generated if you are calling this inline i.e.
echo "<p><a href='set-detail.php?recordID=".$row['post_ID']."'>".$row['title']."</a></p>";
You do not echo the string above.
After your loop you need to echo it.
if(mysqli_affected_rows($link)!=0){
while($row = mysqli_fetch_array($result,MYSQLI_ASSOC)){
echo '<p> <b>'.$row['title'].'</b> '.$row['post_ID'].'</p>' ;
$string .= "<p><a href='set-detail.php?recordID=".$row['post_ID']."'>".$row['title']."</a></p>";
}
echo $string;

Categories