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;
Related
I am trying to check if a number say 1 is present in a string say 11,12,13 To do this I am using strpos:
<?
$s = "2,3,11,12,13";
$ss = "1";
if(strpos($s, $ss)) echo "success";
else echo "fail";
?>
Here I am expecting the code to give fail as output but it gives success.
Is there any function I can use to exactly match the number in a string. I want the number 1 in the string, not the numbers containing 1 like 11,123,100 etc.
Edit 1: It works fine for #Twinfriends answer but the problem is doing it with multiple numbers.
<?
$s = "2,3,11,12,13";
$ss = "1,2";
if(strpos($s, $ss)) echo "success";
else echo "fail";
?>
This code gives output fail but it should give true.
Edit 2: Check answer https://stackoverflow.com/a/48297002/8490014
The problem has been solved but because of for each loop the output is getting repeated as many times as there are values in the array. How can we get the output repeating the output?
You could do it like this:
<?php
$s = "2,3,11,12,13";
$ss = "1";
$toTest = explode(",", $s);
if(in_array("$ss", $toTest)) {
echo "success";
}
else {
echo "fail";
}
?>
If you've any question considering this code, feel free to ask. (Code tested, works well)
The problem has been solved by adding a foreach loop:
<?
$s = "2,3,11,12,13";
$ss = "1,2,3,5";
$catid = explode(",", $s);
$ocat = explode(",",$ss);
foreach($ocat as $abc) {
if(in_array($abc, $catid)) {
echo "success";
}
else {
echo "fail";
}
}
?>
Try this:
<?php
$s = "2,3,11,12,13";
$ss = "1";
$haystack = explode(",",$s);
$matches = preg_grep ("/$ss/", $haystack);
echo !empty($matches) ? "success" : "fail";
You can check by appending comma after the variable to check occurrence at start, appending comma before the variable to check occurrence at last or appending comma before and after the variable to check occurrence at middle.
if((substr($s, 0, (strlen($ss)+1)) === $ss.',')||(substr($s, (strlen($s)-strlen($ss)-1), strlen($s)) === ','.$ss)||(strpos($s, ','.$ss.','))){
echo "success";
}
else{
echo "fail";
}
I got this error and I don't really know why.
switch($op)
{
case "check" :
$result = $Login->login($data,array());
break;
}
echo json_encode($result);
and, it's not echoing the string.
if I put an echo before or after, it works
echo json_encode($result);
echo '.';
returns
{"status":false,"errID":4,"errTxt":"Invalid password"}.
var_dump returns
string(50ish) "{"status":false,"errID":4,"errTxt":"Invalid password"}"
Any ideeas why it's not echoing it without other stuff echoed too?
Edit
$str = json_encode($result);
echo $str;
returns nothing but
$str = json_encode($result);
$str .= '-';
echo $str;
returns
{"status":false,"errID":3,"errTxt":"Invalid email"}-
So it won't echo the string, but if I append something after it, it will echo it.
LE: with die() after echo sill nothing
How do I make this line of code work?
echo $row['Headings'.' '.'Contents']; //
I want to display what's in the 'Headings' column from the database, then a page break, then what's in the 'Contents' column in the db. Please help.
Try this
echo $row['Headings'] .'<br />'. $row['Contents'];
echo $row['headings'] . ' ' . $row['contents'];
Should do the trick.
You can use it as :
$result = mysql_query('select concat(Headings, Contents) as final_string from table_name');
while ($row = mysql_fetch_assoc($result)){
echo $row['final_string'];
}
Please correct me if I am wrong.
Set glue
$glue = "<br />"; // or even what you want
Store it in one variable
$variable = $row['Headings'];
$variable .= $glue;
$variable .= $row['Contents'];
== OR implode by Array ==
$variable = implode($glue, Array($row['Headings'], $row['Contents']));
And then display
echo $variable;
Just do
echo "{$row['Headings']}<br />{$row['Contents']}";
Or the way I should do it
$headings = $row['Headings'];
$contents = $row['Contents'];
echo $headings.'<br />'.$contents
Try this way :
echo $row['Headings'];
echo '<br />';
echo $row['Contents'];
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.
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';