How to create a multiple hyperlink in in single php line - php

I have tried below code; as you can see in bold line i want to add two hyperlink but i am not getting results.I want to create a variable hyperlink.
<?php
echo "<!DOCTYPE html>";
echo "<html>";
echo "<title> disorders </title>";
echo "<body>";
include ('menu.php');
echo "<br>";
echo "<br>";
$disorder = $_GET ['disorder'];
$sql_disorder= "SELECT * FROM `disorders raw datasets` WHERE `Name of disorder` = '$disorder' ";
if ($result_disorder = mysqli_query($conn, $sql_disorder));
{
echo "<table border='1' cellpadding='2' cellspacing='1'> ";
echo "<tr>";
echo "<th>Accession ID</th>";
echo "<th>Title</th>";
echo "<th>Abstract</th>";
echo "<th>Tissue type</th>";
echo "<th>PMID</th>";
echo "<th>Other information</th>";
echo "</tr>";
while($row_disorder = mysqli_fetch_array($result_disorder))
{
echo "<tr>";
**echo "<td><a href='https://www.ncbi.nlm.nih.gov/geo/query/acc.cgi?acc= href='https://www.ebi.ac.uk/arrayexpress/experiments/" . $row_disorder['Accession ID'] . " ' ' >" . $row_disorder['Accession ID'] . "</a> </td>";**
echo "<td>" . $row_disorder['Title'] . " </td>";
echo "<td>" . $row_disorder['Abstract'] . "</td>";
echo "<td>" . $row_disorder['Tissue type'] . " </td>";
echo "<td><a href='https://www.ncbi.nlm.nih.gov/pubmed/" . $row_disorder['PMID'] . " '>" . $row_disorder['PMID'] . "</a></td>";
echo "<td><a href='disorder_info.php?" . $row_disorder['Other information'] . " ' >" . $row_disorder['Other information'] . "</a></td>";
echo "</tr>";
}
echo "</table>";
}
echo "</body>";
echo "</html>";
?>

I don't know why you are using two href in a single tag, that does not support by any dom. Although replace your code with the following line.
echo "
<td><a href='https://www.ncbi.nlm.nih.gov/geo/query/acc.cgi?acc=' href='https://www.ebi.ac.uk/arrayexpress/experiments/' " . $row_disorder['Accession ID'] . " ' '>" . $row_disorder['Accession ID'] . "</a> </td>";

You will have to use urlencode for it to work
$queryString = urlencode("href='https://www.ebi.ac.uk/arrayexpress/experiments/{$row_disorder['Accession ID']}'");
echo "
<td>
<a href='https://www.ncbi.nlm.nih.gov/geo/query/acc.cgi?acc=$queryString'>
{$row_disorder['Accession ID']}
</a>
</td>";

Related

How to add "book button to each car product"?

I want to add "book" button to each car product.But it only display only one button for first car only.
$sql = "SELECT * FROM car";
if($result = mysqli_query($link, $sql)){
if(mysqli_num_rows($result) > 0){
echo "<table>";
echo "<tr>";
echo "<th>Id</th>";
echo "<th>Name</th>";
echo "<th>Price(RM)</th>";
echo "<th>Colour</th>";
echo "<th>Mode</th>";
echo "<th>Image</th>";
echo "<th>Status</th>";
echo "<td><button onclick=\"book_car('" . $row['car_id'] .
"')\">Book</button></td>";
while($row = mysqli_fetch_array($result)){
echo "<tr>";
echo "<td>" . $row['car_id'] . "</td>";
echo "<td>" . $row['car_name'] . "</td>";
echo "<td>" . $row['car_price'] . "</td>";
echo "<td>" . $row['car_colour'] . "</td>";
echo "<td>" . $row['car_mode'] . "</td>";
echo "<td><img src='" . $row['car_image'] . "' height='100'
width='100'></td>";
echo "<td>" . $row['car_status'] . "</td>";
echo "</tr>";
}
There is no error.But i just want "book" button display for each car products.
This is simply because your button is out of the while loop !
Also you did not close first tr tag .
Correct code :
$sql = "SELECT * FROM car";
if($result = mysqli_query($link, $sql)){
if(mysqli_num_rows($result) > 0){
echo "<table>";
echo "<tr>";
echo "<th>Id</th>";
echo "<th>Name</th>";
echo "<th>Price(RM)</th>";
echo "<th>Colour</th>";
echo "<th>Mode</th>";
echo "<th>Image</th>";
echo "<th>Status</th>";
echo "<th>action</th>";<!-- Added this line -->
echo "</tr>";<!-- Added this line -->
while($row = mysqli_fetch_array($result)){
echo "<tr>";
echo "<td>" . $row['car_id'] . "</td>";
echo "<td>" . $row['car_name'] . "</td>";
echo "<td>" . $row['car_price'] . "</td>";
echo "<td>" . $row['car_colour'] . "</td>";
echo "<td>" . $row['car_mode'] . "</td>";
echo "<td><img src='" . $row['car_image'] . "' height='100'
width='100'></td>";
echo "<td>" . $row['car_status'] . "</td>";
echo "<td><button onclick=\"book_car('" . $row['car_id'] .
"')\">Book</button></td>";<!-- Replaced This line -->
echo "</tr>";
}
echo "</table>";
I hope this helps you :)

how to use 2 fetch_assoc in one while loop?

i need list something like this.
First table is display By using the this code.
<?php
if (isset($_REQUEST['asign'])) {
include 'includes/connection.php';
$sql12= $cid->query("SELECT name FROM user WHERE designation='Technical' AND status='1'");
$query = "SELECT * FROM allinone WHERE flag=3 ORDER BY id ASC";
$rs = $cid -> query($query);
$n = $rs -> num_rows;
echo "<br /><span style='color:red;'><center>$n records found</center></span>";
echo "<div id='record'>";
echo "<table border='1' width='80%' align='center' cellpadding='0' cellspacing='0' id='unsolTable'>";
echo "<tr>";
echo "<th>ID</th>";
echo "<th>Ticket Number</th>";
echo "<th>KOID</th>";
echo "<th>PROBLEM</th>";
echo "<th>COMMENT</th>";
echo "<th>DATE</th>";
echo "<th>TIME</th>";
echo "<th>STATUS</th>";
echo "<th>SOLVED BY</th>";
echo "<th>Assign</th>";
echo "<th>Assigned to</th>";
echo "</tr>";
while ($row = $rs -> fetch_assoc() ) {
echo "<tr>";
echo "<td>" . $row['id'] . "</td>";
echo "<td>" . $row['token'] . "</td>";
echo "<td>" . $row['koid'] . "</td>";
echo "<td>" . $row['problem'] . "</td>";
echo "<td>" . $row['comment'] . "</td>";
echo "<td>" . $row['date'] . "</td>";
echo "<td>" . $row['time'] . "</td>";
echo "<td>" . $row['status'] . "</td>";
echo "<td>" . $row['solvedBy'] . "</td>";
echo "<td><a href='assign.php?qType=technical&name=anshul&id=" . $row['id'] . "'>anshul</a>
<br />
<a href='assign.php?qType=technical&name=kiran&id=" . $row['id'] . "'>kiran</a>
<br />
<a href='assign.php?qType=technical&name=akhilesh&id=" . $row['id'] . "'>akhilesh</a></td>";
echo "<td>" . $row['assTo'] . "-" . $row['assTime'] . "-" . $row['assDate'] . "</td>";
echo "</tr>";
}
echo"</table>";
echo "</div>";
}
?>
On the another side is list on the assign i don't want to write it manually just get from the database how can i do this??
$sql= $cid->query("SELECT name FROM user WHERE designation='Technical' AND status='1'");
while ($row=$sql->fetch_assoc()) {
$name= $row['name'];
}
this is the another code i want to add in first code.
Nothing prevents you from executing another SQL query inside you while loop; just replace the echo...anshul...echo...kiran... part with another while loop containing the code you already provided.
You just have to make sure that you use different variables, otherwise your $row variable is overwritten by the second query. Hence, you can do something like this:
// ...
echo "<td>" . $row['solvedBy'] . "</td>";
$resultSetAssignedUsers = $cid->query("SELECT name FROM user WHERE designation = 'Technical' AND status = '1'");
while ($rowAssignedUsers = $resultSetAssignedUsers->fetch_assoc()) {
echo "<td><a href='assign.php?qType=technical&name=" . $rowAssignedUsers['name'] . "&id=" . $row['id'] . "'>" . $rowAssignedUsers['name'] . "</a>";
}
echo "<td>" . $row['assTo'] . "-" . $row['assTime'] . "-" . $row['assDate'] . "</td>";
// ...

remove black block (css,php)

i have this code for result page:
http://pastebin.com/XK3hdNYY
and this css
http://pastebin.com/rs22p4px
but i have a black block that has nothing to do with css.
For example, when the code is this
echo "<tr>";
echo "<td width='auto' bgcolor=”#FF0000 ″>" . " ". "<b>" . $i . " ". "<b/>". "</td>";
echo "<td width='auto'>" . " " . $row[1] . " " . "</td>";
echo "<td width='auto'>". $row[2] . "</td>";
echo '<td><span class="spoiler-label">'.$row[1].'</span><div class="spoiler-content" style="display: none"><br>'.$row[3].'</div><td>';
echo "</tr>";
i have this table output
when i change the code like this
echo "<tr>";
echo "<td width='auto' bgcolor=”#FF0000 ″>" . " ". "<b>" . $i . " ". "<b/>". "</td>";
echo "<td width='auto'>" . " " . $row[1] . " " . "</td>";
echo "<td width='auto'>". $row[2] . "</td>";
echo "<td width='auto'>". $row[3] . "</td>";
echo '<td><span class="spoiler-label">'.$row[1].'</span><div class="spoiler-content" style="display: none"><br>'.$row[3].'</div><td>';
echo "</tr>";
I have this output:
and when i change like this
echo "<tr>";
echo "<td width='auto' bgcolor=”#FF0000 ″>" . " ". "<b>" . $i . " ". "<b/>". "</td>";
echo "<td width='auto'>" . " " . $row[1] . " " . "</td>";
echo "<td width='auto'>". $row[2] . "</td>";
echo '<td><span class="spoiler-label">'.$row[1].'</span><div class="spoiler-content" style="display: none"><br>'.$row[3].'</div><td>';
echo "<td width='auto'>". $row[3] . "</td>";
echo "</tr>";
my output:
I want remove these black block an and the column too. In the third case, it seems that the column has lost its borders and lines?
Looks like you have an HTML syntax error:
echo '<td><span class="spoiler-label">'.$row[1].'</span><div class="spoiler-content" style="display: none"><br>'.$row[3].'</div><td>';
Should be:
echo '<td><span class="spoiler-label">'.$row[1].'</span><div class="spoiler-content" style="display: none"><br>'.$row[3].'</div></td>';
See the closing </td> at the end of each line. You're opening a new column mistakenly.
A new column without a <th> to represent it will default to a blank column like this.

PHP How to echo a different image every 10th row of my results

I have a simple search engine which echo's out results in a table with CSS formatting, this is working fine, however, i would now like to echo a different image after every 10 results.
thankyou to any one who can help me as I have been stuck on this for hours!
this is my echo output code:
echo "<table width='50%' style='border-bottom:1px solid #000000;'";
echo "<tr>";
echo "<td>";
echo "<div id='page-wrap'>";
echo "<div class='discounted-item freeshipping'>";
echo "<a href='./img/users/" . $row['category'] . "/" . $row['username'] . "/" . $row['filename'] . "' rel='lightbox'><img src=\"./img/users/" . $row['category'] . "/" . $row['username'] . "/" . $row['filename'] . "\" alt=\"\" width='20%' height='98%' /></a>";
echo "<div class='reasonbar'><div class='prod-title' style='width: 70%;'>" .$row['fname'] . "</div><div class='reason' style='width: 29%;'><b>". $row['firstname'] . " " . $row['surname'] ."</b></div></div>";
echo "<div class='reasonbar'><div class='prod-title1' style='width: 70%;'>" . $row['lname'] . "</div><div class='reason1' style='width: 29%;'>Category: ". $row['category'] . "</div></div>";
echo "<div class='reasonbar'><div class='prod-title2' style='width: 70%;'>Contact:" . $row['contact'] . "</div><div class='reason2' style='width: 29%;'>Price: £". $row['price'] . "</div></div>";
echo "</td>";
echo "</tr>";
echo "</td>";
echo "</tr>";
echo "</table>";
}
}
else
echo "No results found for \"<b>$search</b>\"";
You can use modolus operator to determine that...
if ( ! ($i % 10)) {
// Alternate.
}
If you don't have a counter variable at your disposal, just declare one outside of your loop and set it to 0 and increment it for each iteration.

Trying to create category wise filtering in the view where i list stuff and getting an error in php?

I have a simple crud application where i am listing certain information . i need to create a filter on the basis of category but am getting an error.
I get the error:
Notice: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'mysql_real_escape_string()' at line 1 in C:\wamp\www\media universe\list.php on line 6
Also tell me if I am going wrong with the filtering.
<?php
include('config.php');
$result = mysql_query("SELECT * FROM `media_universe`") or trigger_error(mysql_error());
if (isset($_POST['submitted_filter'])) {
$filter_category= $_POST[category_filter];
$result = mysql_query("SELECT * FROM `media_universe` where category= '%s',mysql_real_escape_string($filter_category)") or trigger_error(mysql_error());
}
?>
<form action='' method='POST'>
<p><b>Category:</b> <select name="category">
<option>All</option>
<option>Lifestyle</option>
<option>Automobiles</option>
<option>FoodandBeverage</option>
<option>Health</option>
<option>IT</option>
<option>Telecom</option>
<option>EntertainmentandCelebrity</option>
<option>Education</option>
<option>BankingInvestmentandInsurance</option>
<option>Travel</option>
<option>Sports</option>
<option>Parenting</option>
<option>ConsumerElectronics</option>
<option>RealtyandLogistics</option>
<option>CauseLed</option>
</select>
<p><input type='submit' value='Filter' /><input type='hidden' value='1' name='submitted_filter' />
</form>
<?php
include('config.php');
echo "<table border=1 >";
echo "<tr>";
echo "<td><b>Id</b></td>";
echo "<td><b>Category</b></td>";
echo "<td><b>Coursedetail</b></td>";
echo "<td><b>Nameofblog</b></td>";
echo "<td><b>Blogdescription</b></td>";
echo "<td><b>Nameofsocialnetworkiforkfac</b></td>";
echo "<td><b>Nameofsocialnetworkifnotorkfac</b></td>";
echo "<td><b>Nameofsocnetcommunity</b></td>";
echo "<td><b>Numberofmembersinsocnetcommunity</b></td>";
echo "<td><b>Nameofdiscussionforum</b></td>";
echo "<td><b>Descriptionofdiscussionforum</b></td>";
echo "<td><b>NameofQNAsite</b></td>";
echo "<td><b>Nameofnewssite</b></td>";
echo "<td><b>DescriptionofQNAsite</b></td>";
echo "</tr>";
while($row = mysql_fetch_array($result)){
foreach($row AS $key => $value) { $row[$key] = stripslashes($value); }
echo "<tr>";
echo "<td valign='top'>" . nl2br( $row['id']) . "</td>";
echo "<td valign='top'>" . nl2br( $row['category']) . "</td>";
echo "<td valign='top'>" . nl2br( $row['coursedetail']) . "</td>";
echo "<td valign='top'>" . nl2br( $row['nameofblog']) . "</td>";
echo "<td valign='top'>" . nl2br( $row['blogdescription']) . "</td>";
echo "<td valign='top'>" . nl2br( $row['nameofsocialnetworkiforkfac']) . "</td>";
echo "<td valign='top'>" . nl2br( $row['nameofsocialnetworkifnotorkfac']) . "</td>";
echo "<td valign='top'>" . nl2br( $row['nameofsocnetcommunity']) . "</td>";
echo "<td valign='top'>" . nl2br( $row['numberofmembersinsocnetcommunity']) . "</td>";
echo "<td valign='top'>" . nl2br( $row['nameofdiscussionforum']) . "</td>";
echo "<td valign='top'>" . nl2br( $row['descriptionofdiscussionforum']) . "</td>";
echo "<td valign='top'>" . nl2br( $row['nameofQNAsite']) . "</td>";
echo "<td valign='top'>" . nl2br( $row['nameofnewssite']) . "</td>";
echo "<td valign='top'>" . nl2br( $row['descriptionofQNAsite']) . "</td>";
echo "<td valign='top'><a href=edit.php?id={$row['id']}>Edit</a></td><td><a href=delete.php?id={$row['id']}>Delete</a></td> ";
echo "</tr>";
}
echo "</table>";
echo "<a href=new.php>New Row</a>";
?>
Your error, as the error message states, is here:
"SELECT * FROM `media_universe` where category='%s',mysql_real_escape_string($filter_category)"
You're constructing the string incorrectly. You were probably thinking of using sprintf, but didn't. This should do it:
"SELECT * FROM `media_universe` where category='" . mysql_real_escape_string($filter_category) . "'"

Categories