PHP - If Result >= 6 Add Link?
How can I add a link when my query result is >= 6 ?
Do I have to use mysql_num_rows? Similar TutorialsI've tried to find an answer in the forum and although there have been posts similar I am unable to covert the answer to fit what I've got (mostly because I know very very little about php - sorry). What I need is one of the results to be added to the end of a url in order to create a link. Basically I have a storefront (www.storefront.com/) and the result NAME can be added onto the end of our url to create a link to the product page. (www.storefront.com/NAME) Code: [Select] <?php $dbhost = ""; $dbuser = ""; $dbpass = ""; $dbname = ""; //Connect to MySQL Server mysql_connect($dbhost, $dbuser, $dbpass); //Select Database mysql_select_db($dbname) or die(mysql_error()); // Retrieve data from Query String $price = $_GET['price']; $taxable = $_GET['taxable']; $weight = $_GET['weight']; // Escape User Input to help prevent SQL Injection $age = mysql_real_escape_string($price); $sex = mysql_real_escape_string($taxable); $wpm = mysql_real_escape_string($weight); //build query $query = "SELECT * FROM Products WHERE taxable = '$taxable'"; if(is_numeric($price)) $query .= " AND price <= $price"; if(is_numeric($weight)) $query .= " AND weight <= $weight"; //Execute query $qry_result = mysql_query($query) or die(mysql_error()); //Build Result String $display_string = "<table>"; $display_string .= "<tr>"; $display_string .= "<th>Name</th>"; $display_string .= "<th>Price</th>"; $display_string .= "<th>Taxable</th>"; $display_string .= "<th>Weight</th>"; $display_string .= "</tr>"; // Insert a new row in the table for each person returned while($row = mysql_fetch_array($qry_result)){ $display_string .= "<tr>"; $display_string .= "<td>'<a href="www.storefront.com/">' . $row[name] . ' </a>'/td>"; $display_string .= "<td>$row[price]</td>"; $display_string .= "<td>$row[taxable]</td>"; $display_string .= "<td>$row[weight]</td>"; $display_string .= "</tr>"; } echo "Query: " . $query . "<br />"; $display_string .= "</table>"; echo $display_string; ?> I know the way it is setup in the code is wrong. Can anyone help me out? Would really appreciate it. Thanks - and again, sorry for my lack of php knowledge. Could anyone please help about making a search result with links. To be specific, I have a list of names in my database. I want to create a search that will list names with links. Its been 5 hours and cant still figure out how it goes. Thank you I'm trying to add a link to edit my results. Not sure the best way to create the link, nothing I've tried works. There's probably a better way than what I've tried: echo 'There were ', mysql_num_rows($result), ' Matching Photographers:'; while ($row = mysql_fetch_array($result)) { echo "<br />Photographer Info:<br />"; echo "Photographer Name: $row[name]<br />"; echo "Photographer Email: $row[email]<br />"; echo "Photographer ID: $row[PHOTOGRAPHERID]<br />"; echo "Photographer Company: $row[c_name]<br />"; echo "Edit Photographer <a href="update.php?id=' . $row[PHOTOGRAPHERID] . '">Here</a>"; } Hi Everyone. I get the following data from a result from database search <?php echo $rsjobs['CompanyURL'];?> It prints out the url but when I try to turn it into a clickable link it does not work Here is the coding I have so far. <a href="<?php echo $rsjobs['CompanyURL'];?>"><?php echo $rsjobs['CompanyURL'];?></a> What am I doing wrong ? please help. Hello. I am working on a php script for searching a database table. I am really new to this, so I used the this tutorial http://www.phpfreaks.com/tutorial/simple-sql-search I managed to get all the things working the way I wanted, except one important and crucial thing. Let me explain. My table consist of three columns, like this: ID(bigint20) title(text) link (varchar255) ============================= ID1 title1 link-1 ID2 title2 link-2 etc... Like I said, I managed to make the script display results for a search query based on the title. Want I want it to do more, but I can't seem to find the right resource to learn how, is to place a "Download" button under each search result with its corresponding link from the table. Here is the code I used. <?php $dbHost = 'localhost'; // localhost will be used in most cases // set these to your mysql database username and password. $dbUser = 'user'; $dbPass = 'pass'; $dbDatabase = 'db'; // the database you put the table into. $con = mysql_connect($dbHost, $dbUser, $dbPass) or trigger_error("Failed to connect to MySQL Server. Error: " . mysql_error()); mysql_select_db($dbDatabase) or trigger_error("Failed to connect to database {$dbDatabase}. Error: " . mysql_error()); // Set up our error check and result check array $error = array(); $results = array(); // First check if a form was submitted. // Since this is a search we will use $_GET if (isset($_GET['search'])) { $searchTerms = trim($_GET['search']); $searchTerms = strip_tags($searchTerms); // remove any html/javascript. if (strlen($searchTerms) < 3) { $error[] = "Search terms must be longer than 3 characters."; }else { $searchTermDB = mysql_real_escape_string($searchTerms); // prevent sql injection. } // If there are no errors, lets get the search going. if (count($error) < 1) { $searchSQL = "SELECT title, link FROM db WHERE title LIKE '%{$searchTermDB}%'"; $searchResult = mysql_query($searchSQL) or trigger_error("There was an error.<br/>" . mysql_error() . "<br />SQL Was: {$searchSQL}"); if (mysql_num_rows($searchResult) < 1) { $error[] = "The search term provided {$searchTerms} yielded no results."; }else { $results = array(); // the result array $i = 1; while ($row = mysql_fetch_assoc($searchResult)) { $results[] = "{$row['title']}<br /> Download - this is the button I want to link to the title results - and maybe other links too - <br /> "; $i++; } } } } function removeEmpty($var) { return (!empty($var)); } ?> <?php echo (count($error) > 0)?"The following had errors:<br /><span id=\"error\">" . implode("<br />", $error) . "</span><br /><br />":""; ?> <form method="GET" action="search?" name="searchForm"> Search for title: <input type="text" name="search" value="<?php echo isset($searchTerms)?htmlspecialchars($searchTerms):''; ?>" /> <input type="submit" name="submit" value="Search" /> </form> <?php echo (count($results) > 0)?"Rezultate lucrari de licenta sau disertatie pentru {$searchTerms} :<br /><br />" . implode("", $results):""; ?> $results = array(); // the result array $i = 1; while ($row = mysql_fetch_assoc($searchResult)) { $results[] = "{$row['title']}<br /> Download - this is the button I want to link to the title results - and maybe other links too - <br /> "; $i++; I would like the results to be displayed like this Results for SearchItem: Result 1 Download | Other link Result 2 Download | Other link etc.... or something like this. So, how do I add the data from the link row into a text(Dowload), within an <a href> tag (well, at least I guess it would go this way) ? My first tries (fueled by my lack of knowledge) where things like $results[] = "{$row['title']}<br /> <a href="{$row['link']}">Download</a> <br /> "; but I keep getting lots of errors, and then I don't know much about arrays and stuff (except basic notions); So there it is. I am really stuck and can't seem to find any workaround for this. Any suggestions? (examples, documentation, anything would do, really) Thanks, Radu I am really lost here with this date issue of mine. The below code is the last part of a query: Code: [Select] $defendercheck_3 = $row_checkifattacked3['atdate']; $defendercheck1_3 = strtotime("$defendercheck_3"); $defendercheck2_3 = date("D", $defendercheck1_3); The query does not return any results as expected, but when echoing the various steps I get following: echo "$defendercheck3"; = nothing (as expected) echo "$defendercheck1_3"; = nothing (as expected) echo "$defendercheck2_3"; = result! (NOT expected) why does it return anything on "date("D", $defendercheck1_3)" when "$defendercheck1_3" is blank? Hello.
I have a bit of a problem. When I fetch the link field from the database.i don't see an actual link on the page.
One more thing, what type of field should I use to store the link in the database? Probably there is where I went wrong.
All help is
Hi I've got this database I created with fields ProductId ProductName Image I've managed to get it to list the ID,productname, and Image urls in a list. My next step is to have the image field actually display an image and make it clickable: heres what I've done so far: Code: [Select] <?php $con = mysql_connect("localhost","root",""); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("productfeed", $con); $result = mysql_query("SELECT * FROM productfeeds"); echo "<table border='0'> <tr> <th>Firstname</th> <th>Lastname</th> <th>Image</th> </tr>"; while($row = mysql_fetch_array($result)) { echo "<tr>"; echo "<td>" . $row['ProductID'] . "</td>"; echo "<td>" . $row['ProductName'] . "</td>"; echo "<td>" . $row['ImageURL'] . "</td>"; echo "</tr>"; } echo "</table>"; mysql_close($con); ?> Heres what I want to do: Code: [Select] while($row = mysql_fetch_array($result)) { echo "<tr>"; echo "<td>" . $row['ProductID'] . "</td>"; echo "<td>" . $row['ProductName'] . "</td>"; // my changes beneath echo "<td>" . <a href="<?php echo $row['ImageURL'];?>"> <img src="<?php echo $row['LinkURL']; ?>"> </a>. "</td>"; echo "</tr>"; } echo "</table>"; mysql_close($con); ?> Can you guys point me in the right direction? Many thanks Hi Support, I have a form, where it collects user description input. I can collect the inputs and store it with newline. The issue is - how to collect the http link to actual hyperlink ref during display. The following is my code: <textarea name="description" cols="50" rows="10" id="description"><?php echo str_replace("<br>", "\n", $description);?></textarea></td> For example, User input: Hi, Check it out - http://www.google.com/ I would like to display google link as href so that Viewers can click the link and go to the page. Right now, it is not href and user need to copy the link to new tabs or pages and then it can come. Thanks for your help. Regards, Ahsan here's my code that i've used to send an email. Code: [Select] $link = "<a href=\"http://www.example.com/" . $num . "\">" . $num . "</a>"; $query = "SELECT content FROM emails"; $result = mysql_query($query) or die(); $email_content = mysql_result($result, 0); $email = sprintf($email_content, $first, $name, $from, $link, $record, $rec, $inc, $max); $email_body = stripslashes(htmlentities($email, ENT_QUOTES, 'UTF-8')); // this is sent to another php script via post.... $subject = $_POST['subject']; $message = nl2br(html_entity_decode($_POST['email_body'])); $to = "me@whatever.com"; $charset='UTF-8'; $encoded_subject="=?$charset?B?" . base64_encode($subject) . "?=\n"; $headers="From: " . $userEmail . "\n" . "Content-Type: text/html; charset=$charset; format=flowed\n" . "MIME-Version: 1.0\n" . "Content-Transfer-Encoding: 8bit\n" . "X-Mailer: PHP\n"; mail($to,$encoded_subject,$message,$headers); in the db, emails.content is of the text type and contains several lines of text with %4$s which inserts the value of $link into the body. when the email arrives, there is a link and it appears fine, with the value of $num hyperlinked. however when you click on it it doesn't go anywhere. when copying the link location from the email it gives me x-msg://87/%22http://www.example.com/16 what is x-msg? how can i get this to work properly? hi hope you all are fine. i have been working on a Email Form (like user fills up the form which send the information to our email) but i was having problem with (URL field i created) link of form is (http://services.shadowaura.com/allquotations/static.php) field which is not working is "Inspirational Website:" when i submit the form it says (Forbidden You don't have permission to access /allquotations/staticworking.php on this server. Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.) Can some one help me out ????????????? code behind this form is: Code: [Select] <?php /* Email Variables */ $emailSubject = 'Shadow Aura Contact Info!'; $webMaster = '*****@shadowaura.com'; /* Data Variables */ $Name = $_POST['Name']; $email = $_POST['email']; $Cell = $_POST['Cell']; $Phone = $_POST['Phone']; $CompanyName = $_POST['CompanyName']; $TypeOfBusiness = $_POST['TypeOfBusiness']; $Address = $_POST['Address']; $YourBudget = $_POST['YourBudget']; $HaveDomain = $_POST['HaveDomain']; $RunningWeb = $_POST['RunningWeb']; $WebLink = $_POST['WebLink']; $Inspiration1 = $_POST['Inspiration1']; $Inspiration2 = $_POST['Inspiration2']; $NumberPages = $_POST['NumberPages']; $UseFlash = $_POST['UseFlash']; $TimeFrame = $_POST['TimeFrame']; $Provided = $_POST['Provided']; $Comments = $_POST['Comments']; $body = <<<EOD <h1> Static Website Quotation </h1> <br> <b>Name of Client:</b>$Name<br> <b>Your Email:</b>$email<br> <b>Cell Number:</b>$Cell<br> <b>Line Phone Number:</b>$Phone<br> <b>Company Name:</b>$CompanyName<br> <b>Type of Business:</b>$TypeOfBusiness<br> <b>Address:</b>$Address<br> <b>Your Budget:</b>$YourBudget <br> <b>Do you have Domain:</b>$HaveDomain<br> <b>Your Site is Running:</b>$RunningWeb <br> <b>Website Link:</b><a href="$WebLink">$WebLink</a><br> <b>Inspiration:</b>$Inspiration1<br> <b>2nd Inspiration:</b>$Inspiration2<br> <b>Number of Pages:</b>$NumberPages<br> <b>Use Flash:</b>$UseFlash <br> <b>Time Frame:</b>$TimeFrame<br> <b>You will provide:</b>$Provided<br> <b>Comments:</b>$Comments<br> EOD; $headers = "From: $email\r\n"; $headers .= "Content-type: text/html\r\n"; $success = mail($webMaster, $emailSubject, $body, $headers); /* Results rendered as HTML */ $theResults = <<<EOD <html> <head> <title>sent message</title> <meta http-equiv="refresh" content="3;URL=http://services.shadowaura.com/"> <style type="text/css"> <!-- body { background-color: #8CC640; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 20px; font-style: normal; line-height: normal; font-weight: normal; color: #fec001; text-decoration: none; padding-top: 200px; margin-left: 150px; width: 800px; } --> </style> </head> <div align="center">Your email will be answered soon as possible! You will return to <b>Shadow Aura Services</b> in a few seconds !</div> </div> </body> </html> EOD; echo "$theResults"; ?> Ok i call a function like so ... <?php PunchTime($monday,"in","1",$etime_who); ?> Below is the function, if you look closely i echo the query after it's been ran, and that query works 100% since i copied & pasted the query into the database and it returns a result that's needed. But for some bloody reason it doesn't work via code. function PunchTime($pdate,$type,$num,$ewho) { if($type == "in") { if($num == "1") { $etime_col = "PUNCH_IN"; } elseif($num == "2") { $etime_col = "PUNCH_IN2"; } } elseif($type == "out") { if($num == "1") { $etime_col = "PUNCH_OUT"; } elseif($num == "2") { $etime_col = "PUNCH_OUT2"; } } include_once('oracleCON.php'); $etime_qry = "SELECT $etime_col FROM tablename WHERE who= '$ewho' AND punch_date = '$pdate'"; echo $etime_qry; $etime_go = oci_parse($conn, $etime_qry); oci_execute($etime_go); $etime_res = oci_fetch_assoc($etime_go); $time = $etime_res[$etime_col]; if($time == "") $time = "--"; echo $time; } All i get are "--" even though some should return a time stamp. Basically I want this to do do is: if (there is no result found in the query){ echo "nothing for this brand"; }else{ echo this link; } this is my code...im just confused on what i want the if statement to to ask for. any help would be greatly appreciated Code: [Select] <?php $mypro = mysql_query("SELECT * FROM Sheet1 WHERE pro_catagory LIKE '%People%' ORDER BY pro_id DESC"); while($row=mysql_fetch_array($mypro)) { if(Not sure what to put here){ echo "There are no listings for the brand right now"; }else{ print "- <a href='proList.php?proNumber=".$row['pro_id']."'>".$row['pro_name']."</a><br />"; } } ?> at the moment i have my page: addevent.php i have written: Code: [Select] $q = "SELECT username " ."FROM ".TBL_USERS." ORDER BY ASC"; $result = $database->query($q); on the database.php page here is what query looks like: Quote /** * query - Performs the given query on the database and * returns the result, which may be false, true or a * resource identifier. */ function query($query){ return mysql_query($query, $this->connection); } then i want to display $result in a drop down menu so i wrote back on addevent.php: Code: [Select] <select name="Select1"> <option value="<? echo("$result"); ?>"><? echo("$result"); ?></option> </select> i have a game script and it's always bringing back the same result and i cant see why.. all i get when the script it ran is [/code]echo '<div class=noticeBox><h2>Sorry! No available member found![/code] the code is below and can provide the functions and db if needed, but cant see what's wrong. Code: [Select] <?php include '../header.php'; echo '<div id=AjaxSubDiv>'; echo '<div id="actionDiv">'; include '../statusbar.php'; echo '<div id=contentBox>'; // Show Fight Result if( !empty($_GET[action]) AND $_GET[action]=='attack' ) { echo $str; // Fight Lists echo '<P class=pageheader>Fight</P>'; echo '<P>Its time for action! Fight with rival thieves and grab their cash. You will require 1 strength for each fight and you will gain some cash and exp if you win the fight. However you will just earn some exp if you loose!! Each fight will decrease your health so keep an eye on health level because if your health goes below zero you will die and loose everything...</P>'; $res = query("SELECT COUNT(*) FROM `usertable` WHERE `userid`!=$user"); list($total) = mysql_fetch_array($res); if( $total>0 ) { $res = query("SELECT * FROM `usertable` WHERE `userid`!=$user LIMIT 0,20"); $viewplayer = Player::getById($row[userid]); echo '<tr>'; echo '<td width=120px>'; echo '<P class=titleP><a href="#" onclick="load_menu_val(\'AjaxSubDiv\', \'profile\', '.$row[userid].');return false;"><fb:profile-pic uid="'.$row[userid].'" size="square" linked="false" width="75px" class="userImg" /></a></P>'; echo '<P class=titleP><a href="#" onclick="load_menu_val(\'AjaxSubDiv\', \'profile\', '.$row[userid].');return false;"><fb:name uid="'.$row[userid].'" linked="false" /></a></P>'; echo '</td>'; echo '<td width=120px>'; echo '<P><B>Level:</B> '.$viewplayer->level.', '.get_level_title($player->level).'</P>'; echo '</td>'; echo '<td width=120px>'; echo '<P><B>Crew:</B> '.$viewplayer->crew.'</P>'; echo '</td>'; echo '<td width=300px>'; if( $viewplayer->health > 20 ) { echo '<form id="FightForm'.$row[userid].'" method="POST" class="itemForm">'; echo '<input type=hidden name=user value="'.$user.'">'; echo '<input type=hidden name=opid value="'.$row[userid].'">'; echo '<input type=hidden name=action value="dofight">'; echo '<P><input type=button onclick="do_submit(\'FightForm'.$row[userid].'\',\'http://www.bofs.us/thief/thiefmaster/fight/post_fight.php\', \'actionDiv\'); return false;" value="Fight Now" class="submitButton" /></P>'; echo '</form>'; } else { echo '<P class=titleP>Too Weak To Fight</P>'; } echo '</td>'; echo '</tr>'; } echo '</table>'; echo '</center>'; } else { echo '<div class=noticeBox><h2>Sorry! No available member found!</h2></div>'; print"$res"; } echo '</div>'; // end of contentBox echo '</div>'; // end of actiondiv echo '</div>'; // end of AjaxSubDiv ?> I'm writing an admin panel for my site (to manage users, etc) I selected the user-rights from the DB, but how can I check it the user-rights is equal to 3, and if it is allow access? $name = $name . "<option value=". $row['name'] . ">" .$row['name'] . "</option>"; but the name is "Mr. Robert",it does have dot symbol...how to overcome? please help Hey Everyone, I am posting today because I have a site I am working on which uses the xzero classifieds and having a small problem accomplishing something with it. I am trying to relocate the ad count number (of the city the user is currently browsing) to a box in my sidebar which has various site statistics like the following Online Users: XX Ads in this city: 0 But my code keeps giving me a 0 (even after I posted some test ads) Anywho, heres what I have so far but cant seem to make it work <?php $country_adcounts = array(); $city_adcounts = array(); $sql = "SELECT ct.cityid, c.countryid, COUNT(*) as adcnt FROM $t_ads a INNER JOIN $t_cities ct ON ct.cityid = a.cityid AND ($visibility_condn) INNER JOIN $t_countries c ON ct.countryid = c.countryid WHERE ct.enabled = '1' AND c.enabled = '1' GROUP BY ct.cityid"; $res = mysql_query($sql) or die(mysql_error().$sql); while($row=mysql_fetch_array($res)) { $country_adcounts[$row['countryid']] += $row['adcnt']; $city_adcounts[$row['cityid']] += $row['adcnt']; } $adcount = 0+$city_adcounts[$city['cityid']]; ?> and this is the code which should recall the adcount <?php echo $adcount; ?> What am I doing wrong? I'm placing the first code on my sidebar and attempting to call the ad count through an echo. So ya, if anyone could tell me why this isn't working or lend a hand in helping me fix it please know I'll greatly appreciate it. Thanks. Hi i got a search form and when im searhing for result i get nothing. i got 5 search fields : 1. Erea 2. category 3. subcategory 4. from price 5. to price if im not specifieing from price and to price i get blank result ,if i do specify the from price to price ,then i get the results. this is the code im using to get the results. Code: [Select] $sql=mysql_query("select * from posts where erea = '$erea' and category = '$category' and sub_category = '$subcategory' and price >= '$fromprice' and price <= '$toprice'"); what i want is to get the result even if i didnt specify the price from, to . thanx Hello, everyone. I am having some trouble figuring this out. I am trying to create a paging bar(so to speak) to display results by page number. Trying to get the paging bar to go as follows... Requested Page The resulting paging bar Page 1 1 2 3 4 5 Page 2 1 2 3 4 5 Page 3 1 2 3 4 5 Page 4 1 2 3 4 5 Page 5 4 5 6 7 8 Page 6 4 5 6 7 8 Page 7 4 5 6 7 8 Page 8 7 8 9 10 11 ...... This is what I have right now that I am trying to get to work. I have changed this so many times and been working on it for 2 days. I think I'm just confusing my self. This can't be that hard.. Code: [Select] <?php echo '<html>'; //---these values changed based on query---- $Page=$_GET["page"]; //the page number requested $AvailablePages=5; //number of pages available after the page requested //---calculations--- $StartPage=round($Page/5)*5; $EndPage=ceil($StartPage/5)*5 ; //the last page number to be displayed in paging if($StartPage<5) {$StartPage=1;} //just looking at variables echo 'page is: ' . $Page . '<br>'; echo '<br>Starting @: ' . $StartPage; echo '<br>Ending @: ' . $EndPage . '<br>'; //--create the paging bar-- $PagingBar=''; while($StartPage<=$EndPage) { if($Page==$StartPage) { $PagingBar=$PagingBar . $StartPage . ''; } else { $PagingBar=$PagingBar . ' <a href="test.php?page=' . $StartPage . '">' . $StartPage . '</a> '; } $StartPage++; } //---show the paging bar-- echo $PagingBar; echo '</html>'; ?> |