PHP - Display Text If One Of These Items Is Present
Hi, I have the following code in a WordPress theme which displays a companies website, Twitter and Facebook links. What I am trying to do is display the text "Useful Links:" if one of the links exists, and hide the text if all are not present. <p>Useful Links:</p> <?php if ( $website = get_the_company_website() ) : ?> <a class="company-website" href="<?php echo esc_url( $website ); ?>" itemprop="url" target="_blank" rel="nofollow"><?php _e('Website', 'jobseek'); ?></a> <?php endif; ?> <?php if ( get_the_company_twitter() ) : ?> <a class="company-twitter" href="http://twitter.com/<?php echo get_the_company_twitter(); ?>" target="_blank"><?php _e('Twitter', 'jobseek'); ?></a> <?php endif; ?> <?php $facebook_link = get_post_meta( get_the_ID(), '_facebook_link', true ); if ( ! empty($facebook_link) ) : ?> <a class="company-facebook" href="<?php echo $facebook_link; ?>" target="_blank">Facebook</a> <?php endif; ?> What would be the best way to show/hide the text depending on if the items are present or not? Thanks Similar TutorialsHi all I have a MySQL data base that is saving information from a form. One the form a user can add a business name which is text and a logo if they have one. Now on my web page I want to beabe to display the picture if present if not I would like it to display the business name. How do I do this please. I know how to conect to DB etc just having problems getting my head around this problem. Hi guys, I've got a line of code that asks for a column called "distance_completed" to be displayed as part of a string. This column tells users how far people have run in a running race. I set up this field in my database to 11,3 so all distances appear with a decimal at the end, and then 3 digits after the decimal place. How would I alter the code so that the numbers that don't have any information in the places section just appear as integers Eg: 42 instead of 42.000 (for someone who ran exaclty 42km) and those that do have information in the decimal places appear correctly (eg: if a person ran 42km and 195m, it would appear as 42.195). I think this is probably the only line of code that would need modification: Code: [Select] echo ($row['time'] != null)?$row["time"]:"dnf at ".$row["distance_completed"]."km."; Guys, i want to display ads after 4 items to be displayed. Iam fetching item using mysql database & iam showing 8 items per page. I used below code but its not working because i used the item id to specify the first number but the items is not listed as correct order Code: [Select] <?php // first number $first = $row['id']; // second number $second = 4; //checking if the first number is muliple of second. If true then display ads. If($first % $second == "0") { echo 'ads to display'; } It will work if i list items in correct order. Please let me know correct solution. Thanks in advance ! How to display items like bottom table?
And here is the code
<? print" <table style=\"width:100%\" class=\"tableList\"> <tr> <th style=\"width:35%\">Prize Name</th> <th style=\"width:12%\">Amount</th> <th style=\"width:12%\">Points</th> <th style=\"width:12%\">Available</th> <th style=\"width:12%\">Redeemed</th> <th style=\"width:17%\">Action</th> </tr>"; $giftCardQuery = 'SELECT currency, amount, pointsPrice, instant_gift_cards.id, instant_gift_cards.giftCardName, instant_gift_cards.giftCardImage FROM instant_gift_card_codes INNER JOIN instant_gift_cards ON (instant_gift_card_codes.giftCardId = instant_gift_cards.id) WHERE instant_gift_cards.status = :cardStatus ORDER BY instant_gift_cards.dateCreated DESC'; $giftCard = $db->prepare($giftCardQuery); $giftCard->bindValue(':cardStatus', 'Enabled', PDO::PARAM_STR); $giftCard->execute(); if($giftCard->rowCount() > '0'){ while($giftCardRow = $giftCard->fetch(PDO::FETCH_ASSOC)){ $giftCardsAvailableQuery = 'SELECT count(*) FROM instant_gift_card_codes WHERE currency = :currency AND amount = :amount AND pointsPrice = :pointsPrice AND giftCardId = :id AND status = :status'; $giftCardsAvailable = $db->prepare($giftCardsAvailableQuery); $giftCardsAvailable->bindParam(':currency', $giftCardRow['currency'], PDO::PARAM_STR); $giftCardsAvailable->bindParam(':amount', $giftCardRow['amount'], PDO::PARAM_STR); $giftCardsAvailable->bindParam(':pointsPrice', $giftCardRow['pointsPrice'], PDO::PARAM_STR); $giftCardsAvailable->bindParam(':id', $giftCardRow['id'], PDO::PARAM_INT); $giftCardsAvailable->bindValue(':status', 'Available', PDO::PARAM_STR); $giftCardsAvailable->execute(); $gCardsAvailable = $giftCardsAvailable->fetch(PDO::FETCH_COLUMN); $giftCardsRedeemedQuery = 'SELECT count(*) FROM instant_gift_card_codes WHERE currency = :currency AND amount = :amount AND pointsPrice = :pointsPrice AND giftCardId = :id AND status = :status'; $giftCardsRedeemed = $db->prepare($giftCardsRedeemedQuery); $giftCardsRedeemed->bindParam(':currency', $giftCardRow['currency'], PDO::PARAM_STR); $giftCardsRedeemed->bindParam(':amount', $giftCardRow['amount'], PDO::PARAM_STR); $giftCardsRedeemed->bindParam(':pointsPrice', $giftCardRow['pointsPrice'], PDO::PARAM_STR); $giftCardsRedeemed->bindParam(':id', $giftCardRow['id'], PDO::PARAM_INT); $giftCardsRedeemed->bindValue(':status', 'Redeemed', PDO::PARAM_STR); $giftCardsRedeemed->execute(); $gCardsRedeemed = $giftCardsRedeemed->fetch(PDO::FETCH_COLUMN); if($giftCardRow['giftCardImage']){ $nameOrImage = '<img src="./images/giftcardrewards/'.$giftCardRow['giftCardImage'].'" alt="'.$giftCardRow['giftCardName'].'" title="'.$giftCardRow['giftCardName'].'">'; }else{ $nameOrImage = $giftCardRow['giftCardName']; } if($gCardsAvailable == '0'){ $redeemAction = 'Out of Stock'; } elseif($userInfo['currentPoints'] < $giftCardRow['pointsPrice']){ $needed = $giftCardRow['pointsPrice'] - $userInfo['currentPoints']; $redeemAction = 'You need '.$needed.' point(s)'; } elseif($userInfo['currentPoints'] >= $giftCardRow['pointsPrice']){ $redeemAction = '<input type="button" value="Redeem" onclick="if(confirm(\'Are you sure to redeem this prize?\')){location.href=\'index.php?do=instantGiftCards&action=redeem&cardId='.$giftCardRow['id'].'&amount='.$giftCardRow['amount'].'\';}">'; } print" <tr> <td>".$nameOrImage."</td> <td style=\"text-align:center\">".$giftCardRow['currency'].$giftCardRow['amount']."</td> <td style=\"text-align:center\">".$giftCardRow['pointsPrice']."</td> <td style=\"text-align:center\">".$gCardsAvailable."</td> <td style=\"text-align:center\">".$gCardsRedeemed."</td> <td style=\"text-align:center\">".$redeemAction."</td> </tr>"; } }else{ print" <tr> <td colspan=\"4\" style=\"text-align:center;color:#2B1B17;padding:15px 0\">No prizes added.</td> </tr>"; } print" </table>"; ?> I'm working on creating a Realtors website. Currently mysql DB has 4 tables. 3 of them are needed in this script to show up as 1 item. Table called Listings has 2 fields that call on 2 other tables. one is MLS which calls on the Images Table the other agent calls on the Agents table. I'm trying to see why I can't While loop all 3 tables together? How can I connect all 3? <?php if (!function_exists("GetSQLValueString")) { function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") { if (PHP_VERSION < 6) { $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue; } $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue); switch ($theType) { case "text": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "long": case "int": $theValue = ($theValue != "") ? intval($theValue) : "NULL"; break; case "double": $theValue = ($theValue != "") ? doubleval($theValue) : "NULL"; break; case "date": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "defined": $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue; break; } return $theValue; } } //mysql_select_db($database_CarneyRealty, $CarneyRealty); //$query_Update1 = "SELECT * FROM listings"; //$Update1 = mysql_query($query_Update1, $CarneyRealty) or die(mysql_error()); //$rrows = mysql_fetch_assoc($Update1); //$totalRows_Update1 = mysql_num_rows($Update1); include 'dbc.php'; page_protect(); $err = array(); $msg = array(); $page_limit =4; //CHANGE FOR THE NUMBER OF LISTINGS PER PAGE! $page_num_limit =10; $ret = $_SERVER['HTTP_REFERER']; $host = $_SERVER['HTTP_HOST']; $host_upper = strtoupper($host); $login_path = @ereg_replace('admin','',dirname($_SERVER['PHP_SELF'])); $path = rtrim($login_path, '/\\'); // filter GET values foreach($_GET as $key => $value) { $get[$key] = filter($value); } foreach($_POST as $key => $value) { $post[$key] = filter($value); } $rs_all = mysql_query("select count(*) as total_all from listings") or die(mysql_error()); $rs_active = mysql_query("select count(*) as total_active from listings where status='ACTIVE'") or die(mysql_error()); $rs_total_contingent = mysql_query("select count(*) as tot2 from listings where status='CONTINGENT'"); $rs_total_pending = mysql_query("select count(*) as tot from listings where status='PENDING'"); $rs_total_sold = mysql_query("select count(*) as tot1 from listings where status='SOLD'"); $rs_resall = mysql_query("select count(*) as res from listings where class='Resident'") or die(mysql_error()); $rs_comall = mysql_query("select count(*) as com from listings where class='Commerical'"); $rs_farmall = mysql_query("select count(*) as farm from listings where class='Farmland'"); $rs_otherall = mysql_query("select count(*) as other from listings where class='Other'"); list($all) = mysql_fetch_row($rs_all); list($active) = mysql_fetch_row($rs_active); list($total_contingent) = mysql_fetch_row($rs_total_contingent); list($total_pending) = mysql_fetch_row($rs_total_pending); list($total_sold) = mysql_fetch_row($rs_total_sold); list($resall) = mysql_fetch_row($rs_resall); list($comall) = mysql_fetch_row($rs_comall); list($farmall) = mysql_fetch_row($rs_farmall); list($otherall) = mysql_fetch_row($rs_otherall); /////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////////// $sqlagents = mysql_query("select * from agents where id='$_SESSION'"); //$agentname= mysql_query($sqlagents) or die(mysql_error()); $sqllistings = mysql_query("select * from listings where id='$_SESSION'"); $sqlimages = mysql_query("select * from images where id='$_SESSION'"); //////////////////////////////////////////////////////////////////////////////////////////////////////// ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html> <head> <title>Search CarneyRealty Listings</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <link rel="stylesheet" href="../css/mm_brochure.css" type="text/css"> <style type="text/css"> <!-- body { background-image: url(http://www.carneyrealty.com/newsite/images/IMG_0161a.jpg); } .style1 { font-size: 16px } .style2 { font-family: Geneva, Arial, Helvetica, sans-serif } .style10 { font-size: 13px; font-weight: bold; color: #FF0000; } .style7 { color: #FF0000; font-weight: bold; } .style8 { color: #0000FF; font-weight: bold; } --> </style> </head> <body bgcolor="#bcbc85" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0"> <div align="center"> <table width="81%" border="0" cellspacing="0" cellpadding="0"> <tr bgcolor="#999966"> <td width="25" nowrap="nowrap"><center> <img src="../images/mm_spacer.gif" alt="" width="15" height="1" border="0" /></td> <td height="60" colspan="3" class="logo" nowrap="nowrap"><div align="center"><img src="images/Carney_Logo1_000.jpg" width="630" height="158" /><br /> </div></td> <td width="4"></td> </tr> <tr bgcolor="#797947"> <td width="25" nowrap="nowrap"></td> <td colspan="3" valign="top"><div align="center"> <table width="460" border="0" cellpadding="0" cellspacing="0" id="navigation"> <tr> <td width="59" align="center" nowrap="nowrap"><div align="center"><a href="../index.htm" class="style1"><strong>HOME</a></div></td> <td width="127" align="center" nowrap="nowrap"><div align="center"><strong><a href="../SearchCarneyRealtyListings.php" class="style5">LISTINGSEARCH</a></strong></div></td> <td width="94" align="center" nowrap="nowrap"><div align="center"><strong><a href="../Aboutus.html" class="style5">ABOUT US</a></strong></div></td> <td width="10" align="center" nowrap="nowrap"><div align="center"></div></td> <td width="95" align="center" nowrap="nowrap"><div align="center"><strong><a href="../Community.htm" class="style5">COMMUNITY </a></strong></div></td> <td width="81" align="center" nowrap="nowrap"><div align="center"><strong><a href="../Login.php" class="style5">LOGIN</a></strong></div></td> </tr> </table> <table width="307" border="0" cellpadding="0" cellspacing="0" id="navigation"> <tr> <td width="84" align="center" nowrap="nowrap"><div align="center"><a href="http://www.carneyrealty.com/newsite/listingsearch.php?doSearch=MLS+Search&q=Resident" class="style1">Residential</a></div></td> <td width="103" align="center" nowrap="nowrap"><div align="center"><strong><a href="http://www.carneyrealty.com/newsite/listingsearch.php?doSearch=MLS+Search&q=Commerical" class="style5">Commercial</a></strong></div></td> <td width="102" align="center" nowrap="nowrap"><div align="center"><strong><a href="http://www.carneyrealty.com/newsite/listingsearch.php?doSearch=MLS+Search&q=Farmland" class="style5">Farms & Land</a></strong></div></td> <td width="18" align="center" nowrap="nowrap"><div align="center"></div></td> </tr> </table> <table width="573" border="0" cellpadding="0" cellspacing="0" id="navigation"> <tr> <td width="72" align="center" nowrap="nowrap"><div align="center"><a href="residental0-60.php" class="style1">$0-$60K</a></div></td> <td width="80" align="center" nowrap="nowrap"><div align="center"><strong><a href="residental61-85.php" class="style5">$61K-$85K</a></strong></div></td> <td width="87" align="center" nowrap="nowrap"><div align="center"><strong><a href="residental86-115.php" class="style5">$86K-$115K</a></strong></div></td> <td width="1" align="center" nowrap="nowrap"><div align="center"></div></td> <td width="103" align="center" nowrap="nowrap"><div align="center"><strong><a href="residental116-160.php" class="style5">$116K-$160K</a></strong></div></td> <td width="93" align="center" nowrap="nowrap"><div align="center"><strong><a href="residental161-230.php" class="style5">$161K-230K</a></strong></div></td> <td width="126" align="center" nowrap="nowrap"><div align="center"><strong><a href="residential231up.php" class="style5">$231K-And Up</a></strong></div></td> <td width="11" align="center" nowrap="nowrap"> </td> </tr> </table> </div></td> </tr> <td width="25" valign="top"><?php /*********************** MY MLS MENU **************************** This code shows MLS account menu only to logged in users. Copy this code till END and place it in a new html or php where you want to show myaccount options. This is only visible to logged in users *******************************************************************/ ?> <?php if(!empty($msg)) { echo $msg[0]; } ?> <? //$row_settings1=mysql_fetch_array($sqllistings1);?> <?php while ($row_settings1 = mysql_fetch_array($sqllistings)){ $row_settings2=mysql_fetch_array($sqlimages); $row_settings3=mysql_fetch_array($sqlagents); ?> <?php } ?> </table> <table width="81%" border="0" align="center" cellpadding="10" cellspacing="0" style="background-color: #FF9933;padding: 2px 5px;border: 1px solid #F90;" > <tr> <td height="44" align="center"><form name="form1" method="get" action="listingsearch.php"> <p> <input name="doSearch" type="submit" id="doSearch2" value="MLS Search" /> <input name="q" type="text" id="q" size="40"> <strong> S CARNEY& ASSOCIATES INC 800-757-5783</strong> <br> </p> </form></td> </tr> </table> </td> </tr> </table> </div> <p> <?php if ($get['doSearch'] == 'MLS Search') { $cond = ''; if($get['qoption'] == 'active') { $cond = "where `status`='ACTIVE' order by date desc"; } if($get['qoption'] == 'contingent') { $cond = "where `status`='CONTINGENT' order by date desc"; } if($get['qoption'] == 'pending') { $cond = "where `status`='PENDING' order by date desc"; } if($get['qoption'] == 'sold') { $cond = "where `status`='SOLD' order by date desc"; } if($get['qoption'] == 'resident') { $cond = "where `class`='Resident' order by price desc"; } if($get['qoption'] == 'farmland') { $cond = "where `class`='Farmland' order by price desc"; } if($get['qoption'] == 'commerical') { $cond = "where `class`='Commerical' order by price desc"; } if($get['qoption'] == 'other') { $cond = "where `class`='Other' order by price desc"; } //if($get['qoption'] == '') { if($get['q'] == '') { $sql = "select * from listings order by price asc"; // $sql = "select * from listings $cond"; // } } else { $sql = "select * from listings where `price` = '$_REQUEST[q]' or `mls`='$_REQUEST[q]' or `seller`='$_REQUEST[q]' or `class`='$_REQUEST[q]' or `status`='$_REQUEST[q]' order by `price` asc"; //$sql1="select * from images where `mls`='$sql'"; //$sql2="select * from agents where `tag`='$sql'"; // $sql = "select * from listings where `mls`='$_REQUEST[q]' or `price`='$_REQUEST[q]'"; } //$rs_total1=mysql_query($sql1) or die(mysql_error()); $rs_total = mysql_query($sql) or die(mysql_error()); $total = mysql_num_rows($rs_total); // $total1=mysql_num_rows($rs_total1); if (!isset($_GET['page']) ) { $start=0; } else { $start = ($_GET['page'] - 1) * $page_limit; } $rs_results = mysql_query($sql . " limit $start,$page_limit") or die(mysql_error()); $total_pages = ceil($total/$page_limit); // $rs_results1 = mysql_query($sql1 ."limit $start,$page_limit") or die (mysql_error()); ?> <?php // outputting the pages if ($total > $page_num_limit) { echo "<table width='81%' border='0' align='center' cellpadding='2' cellspacing='0' background='#fcfcdd'><span class='subHeader'><center>Pages: "; $i = 0; while ($i < $page_num_limit) { $page_no = $i+1; $qstr = ereg_replace("&page=[0-9]+","",$_SERVER['QUERY_STRING']); echo "<a href=\"listingsearch.php?$qstr&page=$page_no\">$page_no</a> "; $i++; } echo "</span></td></table>"; } ?> <? //while ($rrows3 = mysql_fetch_array($rrows3)){ ?> <form name "searchform" action="listingsearch.php" method="post"> </form> </table> <?php ////////////////////////////////////////////////////////////////////////////// while ($rrows = mysql_fetch_array($rs_results)) { $rrows2=mysql_fetch_array($sqlimages); $rrows3=mysql_fetch_array($sqlagents); /////////////////////////////////////////////////////////////////////////////// //$imagenamevar=($rrows['mls']=$rrows2['mls']); //echo $rrows3['id']; //$agentpicvar=($rrows['seller']=$rrow3['tag']); ?> <tr> <table width="81%" border="0" align="center" cellpadding="2" cellspacing="0" background="#fcfcdd"> <? echo $rrows['agents'.'seller_id'];?> <td width="161" height="211" align="center" valign="top" bgcolor="#fcfcdd"><div align="center"><img src="http://www.carneyrealty.com/newsite/uploads/<?php echo $rrows['mls'];?>/<? echo $mainimagevar; ?> width="214" height="160" /> </p> </div> <p class="tagline">Click for Additional Pictures</p></td> <td width="568" align="center" valign="top" bgcolor="#fcfcdd" class="calendarText"><div align="left"> <table width="592" height="180" border="1"> <tr valign="top"> <td width="74" height="27" bgcolor="#fcfcdd" class="tagline">Location </td> <td width="249" bgcolor="#fcfcdd"><strong><?php echo $rrows['location'];?> <br> <? echo $rrows['location1'];?> <br> <? echo $rrows3['tag'];?> </strong></td> <td width="180" rowspan="2" bgcolor="#fcfcdd" class="tagline"><div align="center"> <table width="180" height="62" border="1"> <tr valign="top"> <td width="70" rowspan="2" class="tagline"><a href="http://www.carneyrealty.com/newsite/upload/<?php echo $rrows['mls'];?>/<? echo "SD_disp.pdf";?>"><img align="absbottom" src="http://www.carneyrealty.com/newsite/Listing_pages/images/datasheet_018.jpg" width="58" height="50" /></a></td> <td width="50" class="tagline"><div align="left">Status </div></td> <td width="68"><div align="right" class="subHeader"><?php echo $rrows['status']; ?></div></td> </tr> <tr valign="top"> <td height="24" class="tagline"><div align="left">PRICE</div></td> <td align="center" valign="top"><div align="right"><strong class="subHeader"><?php echo $rrows['price']; ?></strong></div></td> </tr> </table> <span style="color: #fcfcdd"><strong><a href="mailto:<? echo $rrows['selleremail'];?>"><img src="http://www.carneyrealty.com/newsite/Listing_pages/images/mail_004.gif" width="14" height="15" /><? echo $rrows['seller'];?></a></strong></span></div></td> <td width="61" rowspan="2" bgcolor="#fcfcdd" class="tagline"><div align="right"></div> <span style="color: #fcfcdd"><img src="<? ///////////////////////////////////////////////////////////// while ($rrows3=($rrows['seller']=$rrows3['seller_id'])){ echo $rrows3['agentimage']; } ////////////////////////////////////////////////////////////// ?>" width="60" height="91" /></a></span></td> </tr> <tr valign="top"> <td height="64" bgcolor="#fcfcdd" class="tagline">Specs</td> <td bgcolor="#fcfcdd"><strong><?php echo $rrows['specs']; ?></strong></td> </tr> <tr valign="top"> <td height="77" bgcolor="#fcfcdd" class="tagline">Description</td> <td colspan="3" bgcolor="#fcfcdd" ><strong>MLS #<?php echo $rrows['mls'];?><br> <? echo $rrows['description'];?></strong> <p><strong>Call <? echo $rrows['seller'];?> at <? echo agentnumbervar;?> to view or for more information.</strong></p></td> </tr> </table> <tr> <td height="18" colspan="2" align="center" valign="top" bgcolor="#FF9933"><span class="bodyText style2" style="color: #fcfcdd"></span><span class="bodyText style2">S Carney & Associates Real Estate Brokerage 800 757 5783 </span></td> </tr> </div></td> </tr> </span> <? } ?> <td height="4"></td> </table> <? } ?> <? //} ?> </tr> <?php // outputting the pages if ($total > $page_limit) { echo "<table width='81%' border='0' align='center' cellpadding='2' cellspacing='0' background='#fcfcdd'><span class='subHeader'><center>Pages: "; $i = 0; while ($i < $page_num_limit) { $page_no = $i+1; $qstr = ereg_replace("&page=[0-9]+","",$_SERVER['QUERY_STRING']); echo "<a href=\"listings.php?$qstr&page=$page_no\">$page_no</a> "; $i++; } echo "</span></td></table>"; } ?> </td> </tr> <tr> <td height="22" class="bodyText"><? include 'footer1.shtml'; ?> </td> </tr> <tr> <td height="194" class="bodyText"><div align="center"> <table width="513" border="0"> <tr valign="top"> <th width="94" scope="col"><div align="center"><a href="http://www.realtor.org/technology/crt_secure/home?opendocument"><img src="images/index.1.gif" width="43" height="42" border="0" /></a></div></th> <th width="46" scope="col"><div align="center"></div></th> <th width="100" valign="middle" scope="col"><div align="center" class="style7"> <div align="center"><a href="http://www.nacogdochesmls.com/nag/passwd.php"><img src="images/MLS_a_94-50.gif" width="92" height="51" alt="Multiple Listing Service" /></a></div> </div></th> <th width="119" scope="col"><div align="center"><a href="http://www.hud.gov/offices/fheo/FHLaws/"><img src="http://www.habitatwhitley.org/equal_housing_logo.jpg" alt="Equal Housing Opportunity" width="60" height="62" border="0" /></a></div></th> <th width="129" scope="col"><div align="center"></div></th> </tr> <tr valign="top"> <td height="32"><div align="center" class="style8"><a href="http://www.realtor.org/technology/crt_secure/home?opendocument">REALTOR.ORG</a></div></td> <td><div align="center"></div></td> <td valign="middle"><div align="center"><span class="style10"><a href="http://www.nacogdochesmls.com/nag/passwd.php">Multiple Listing System</a></span></div></td> <td><div align="center"><strong><a href="http://www.hud.gov/offices/fheo/FHLaws/">Equal Housing Opportunity</a></strong></div></td> <td><div align="center"><a href="http://www.bbb.org/">BETTER BUSINESS BUREAU</a></div></td> </tr> </table> </div></td> </tr> </table> <div align="left"> <br /> </div> </div> </td> <td valign="top"><div align="left"></div></td> <td width="4"><div align="left"></div></td> </tr> <tr> <td width="15"> </td> <td width="35"> </td> <td width="698"><div align="center"> <?php include 'footer.shtml'; ?> </div> </td> <td width="1"><div align="center"></div></td> <td width="4"> </td> </tr> </table> </table> </table> </div> </body> </html> PHP script return 20 UL LIST values like, < ul >
A < /ul > How to display UL LIST into row wise 5 columns like
A B C D I have a webpage where all the database items are displyes in a table format.The table also has a check box.Upon clicking the delete button i need to delete all the items whish has the checkbox checked. How will i do that I'm doing an ajax call from javascript using jquery library: Code: [Select] ajaxCall: function(process, obj, type){ $.post("registration-post.php", type + "=" + process, function(data){ if(data==""){ $(obj).css(registration.errorNotificationType, registration.validatedColour); }else{ $('.error').append($.trim(data) + "<br />"); $(obj).css(registration.errorNotificationType, registration.errorColour); registration.progress = false; } } ); } When the ajax calls the php page, I want the php page to know what post information the javascript has sent, rather than pre-defining what the PHP should be trying to retrive from the POST data. Something like // pseudo $_POST["whateverwassentfromajax"] I want to do this because I want to have one function doing everything. So in my javascript I am saying, check if the username and email have already been used... But i dont want to call two different php functions. //pseudo function 1(){ $_POST["username"]; } function 2(){ $_POST["email"]; } Is there a special way to know which post data has been sent. Or do i need to do a few if statements in php. Hello All, I have been wrestling with a regex for a couple of hours now and I finally had to give in and ask for help. The weird thing is that it works if there are no new lines in the text, it fails if there is a new line(s) present. The code: $matches = array(); $pattern = '~\[CUSTOM_TAG(.*?)\](.*?)\[/CUSTOM_TAG\]~'; preg_match_all($pattern, $html, $matches); if (!empty($matches[0])){ foreach($matches[0] as $code){ $parameter = preg_replace($pattern, '$1', $code); $content = preg_replace($pattern, '$2', $code);//get the content between the pattern }//foreach($matches[0] as $code){ }else{ echo 'Match failed'; }//if (!empty($matches[0])){ So with that code in mind, if the $html variable (the text to be processed) is: $html = '<h1>Hello, world!</h1><p style="color:#ff0000;">Some red text</p>';A match is found. If the $html variable is: $html = '<h1>Hello, world!</h1> <p style="color:#ff0000;">Some red text</p>';Match not found Hopefully I'm just missing something simple in my regex. Thanks in advance! Twitch Hi,
I have made a database linked with php that I use a html form for. The HTML form requests a particular date to retrieve, and the php form it is linked to then retrieves data from the MySQL database from that date.
My question is: I want there to be a restriction so that the retrieval can only be for dates before the present date (and certainly not any date in the future).
e.g. if it is 6th July 2020, then the database can only retrieve from the 5th July 2020 and before. (7th July 2020 onwards also is not allowed.) Is there a way I can do it? Anyone who can guide me to a particular code function or something of that sort - I would be deeply grateful as my searches have not come up fruitful. Edited July 10, 2020 by samanjclarity Hi, guys. I want to present different ads to visitors in different countries. For example, if a visitor is in Australia, I want him/her to see a different ad from, say, a visitor from the UK. Can this kind of thing be done with PHP? If so, will installing such a code slow down my site? Any help will be appreciated very much. Hi, I'm hoping someone can help me with a simply array problem. I have a table with two columns: "ID" and "Name" and 100 Names. I also have an array called $myIDList containing 10 IDs. I want to display 10 Names from the table that correspond with the IDs from my array. Originally, I tried to implode the array, adding commas and inserted into my MySQL query using: $myQuery = "SELECT ID, Name FROM namesTable WHERE ID IN ($myImplodedIDList)"; The problem was that duplicated names (i.e. the same Name, but assiged to different IDs) would only be displayed once. So now I'm trying to use the original array to loop through a second array and display Names where the ID matches an ID from my first array. I have succesffuly listed the table like this: $myQuery = "SELECT ID, Name FROM myTable ORDER BY ID"; $myResult = mysql_query($myQuery) or die(mysql_error()); while($row=mysql_fetch_array($myResult)) { echo $row['ID']; echo $row['Name']; } But I want to do something like: while($row=mysql_fetch_array($myResult)) { while $row['ID'] = $myIDList { echo $row['Name'] } } Can someone shed some light onto this for me please? Thank you! Bryan Hoping someone could help me with hiding a video player if a video is not present in the db. I have split up the code to make it easier to understand. Thanks in advance (int) $ListId=$_GET['ListID']; function mysql_resultTo2DAssocArray ( $result) { $i=0; $ret = array(); while ($row = mysql_fetch_assoc($result)) { foreach ($row as $key => $value) { $ret[$i][$key] = $value; } $i++; } return ($ret); -------------------------------------------------------------------------------------------- $querys = mysql_query("SELECT * FROM video WHERE listingID = '$ListId' "); $Details_video=mysql_resultTo2DAssocArray ($querys); -------------------------------------------------------------------------------------------- <div class="right_col"> <p id='preview'>The player will show in this paragraph</p> <script type='text/javascript' src='/flvPlayer/swfobject.js'></script> <script type='text/javascript'> var s1 = new SWFObject('/flvPlayer/player-viral.swf','player','280','200','9'); s1.addParam('allowfullscreen','true'); s1.addParam('allowscriptaccess','always'); s1.addParam('autostart','true'); s1.addParam('image','/flvfiles/<?php echo $Details_video[0]['imagePath']?>'); s1.addParam('flashvars','&file=/flvfiles/<?php echo $Details_video[0]['videoPath']?>&image=/flvfiles/<?php echo $Deatls_video[0]['imagePath']?>&dock=false&autostart=true'); s1.write('preview'); </script> hi friends, I am using one API in which i need to make request for flight search, i am using soapclient to connect with the server to fetch available flights, below is the xml in which request format will be. SOAP 1.1 The following is a sample SOAP 1.1 request. The placeholders shown need to be replaced with actual values. POST /tws_mind/Ws_TravelPortal.asmx HTTP/1.1 Host: 125.16.62.119 Content-Type: text/xml; charset=utf-8 Content-Length: length SOAPAction: "http://tempuri.org/Ws_fnAirAvail" <?xml version="1.0" encoding="utf-8"?> <soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> <soap:Body> <Ws_fnAirAvail xmlns="http://tempuri.org/"> <objReq> <destination> <string>string</string> <string>string</string> </destination> <domestic>boolean</domestic> <journeydate> <dateTime>dateTime</dateTime> <dateTime>dateTime</dateTime> </journeydate> <journeytype>string</journeytype> <Noofadults>int</Noofadults> <Noofchild>int</Noofchild> <Noofinfant>int</Noofinfant> <preferedairlines> <string>string</string> <string>string</string> </preferedairlines> <preferredclass>string</preferredclass> <returndate>dateTime</returndate> <source> <string>string</string> <string>string</string> </source> <strPreferredCarrierType>string</strPreferredCarrierType> <GetCachedData>boolean</GetCachedData> </objReq> <objSecurity> <strLoginId>string</strLoginId> <strPassword>string</strPassword> </objSecurity> </Ws_fnAirAvail> </soap:Body> </soap:Envelope> and below is the request which is made by me. $request=array( 'objReq'=>array('destination' => "DEL", 'domestic' => 1, 'journeydate'=>"25/10/2011", 'journeytype'=>"R", 'Noofadults'=>2, 'Noofchild'=>0, 'Noofinfant'=>0, 'preferedairlines'=>"", 'preferredclass'=>"Y", 'returndate'=>"28/10/2011", 'source'=>"BLR", 'strPreferredCarrierType'=>"ANY", 'GetCachedData'=>false ) 'objSecurity'=>array('strLoginId'=>"loginid", 'strPassword'=>"password" ) ); $wsdl="http://*/*/?wsdl"; try{ $cliente=new SoapClient($wsdl); $vem=$cliente->Ws_fnAirAvail($request); } catch (Exception $e) { echo $e->getMessage(); exit; } echo "<pre>"; print_r($vem); My problem is i am getting below response, if i change the request in anyway i always get the same response. Please correct my request in case i made bad request for the server. stdClass Object ( [Ws_fnAirAvailResult] => stdClass Object ( [objclsException] => stdClass Object ( [errorcode] => GEN0E0006 [errortype] => E [errordesc] => Please provide Security object. ) [strMessage] => ) ) in my code below the **data is extracted correctly for the first foreach but doesn't return anything for 2nd foreach though selected one present inside the 2nd foreach** i still get the error Warning: Invalid argument supplied for foreach() for line `foreach ($authorlist as $post)`... however the 2nd foreach returns data correctly as soon as i remove the first foreach loop. Hello, I have started a DB for simple web based inventory system, I have only dabbled in PHP before 6 weeks ago, within the last 6 weeks with some help and going through countless tutorials and asking questions when I need. At this time setup an insert, delete and update function for this db and are working perfectly, now what I need to know is there a way to display something like 'in stock' and 'out of stock' using php, based on the value of the quantity in my db next to the item in a table?
Example : when the table is generated it will display:
| Part number | Description | Stock | (normally Stock would show the quantity of each part, I just wish to
|10-1111 | Some info | In Stock | display In or out os stock)
|10-1112 | Some Info | Out of Stock |
I the only code I have is the tables and just not sure what to do next to get the results I have described above. So I will include the table code I have and see where we can go from there. Or if you have some webs site that I can read through that will be great as well as long as it can give me basic instruction on how to do this.
Reminder, I am self taught and still learning.
<?php $con = mysqli_connect("localhost","user","pass","part_inventory"); // Check connection if (mysqli_connect_errno()) { printf("Connect failed: %s\n", mysqli_connect_error()); exit(); } else { $result = mysqli_query($con, "SELECT * FROM amp20"); echo "<table border='1'> <tr> <th>ID</th> <th>Part number</th> <th>description</th> <th>location</th> <th>Quantity</th> </tr>"; while ($row = mysqli_fetch_array($result)) { echo "<tr>"; echo "<td>" . $row['amp20ptid'] . "</td>"; echo "<td>" . $row['partnum'] . "</td>"; echo "<td>" . $row['description'] . "</td>"; echo "<td>" . $row['location'] . "</td>"; echo "<td>" . $row['quantity'] . "</td>"; echo "</tr>"; } echo "</table>"; mysqli_close($con); } ?> Edited by Thunder_Wolf, 22 October 2014 - 11:16 AM. Sorry if this is too obvious or hard to understand. I'm echoing a database value onto a webpage, the value in question is a large paragraph of text. I need it to only display the first 40 characters or so of that text, then trail off with a "..." So the users will be able to click a 'More Info' button which will take them to a page containing the full paragraph of text. I'm just not sure how to cut off the text after 40 characters. Any help HUGELY appreciated I have a field in my database called description. How can I echo out only 500 out of the 2000 max characters? Like for example: Code: [Select] $query = mysql_query("SELECT description FROM `servers` ORDER BY votes DESC LIMIT 5"); If I were to echo out the value of description for the database, how can I only echo out the first 500 characters? Hi, Wonder if someone could help with the problem below. Got a main page that includes a header, footer and a link to a database. I can get the two Includes to work but can't seem to display the database fields in the body of the page. What has me baffled is that it appears to be connecting to the database, (Opening the connection to the database server The connection worked. The link is: Resource id #3) but no text (see below for database text) is appearing on the screen. Yet I'm not getting a "page_not_found" message. I can go to the database in MYSQL console and query it successfully. Read and (hopefully) applied the section Debugging: A Beginner's Guide, but still can't see the problem. Any help greatly appreciated. Bren --------------------CODE FOR MAIN PAGE START------------------- <?php $page_name = $_REQUEST['name']; /*http://localhost/exemples/page.php?name=about_us*/ // Get the body of the page mysql_connect("localhost","root","") or die(mysql_error()); mysql_select_db("test") or die(mysql_error()); $sql = "SELECT * from pages WHERE name='$page_name'"; print "Opening the connection to the database server<br>"; $link = mysql_connect("localhost","root", ""); print "The connection worked. The link is: $link <br>"; /* --------------What is being selected from the database-------------- +----------+------------------------------------------------------------------------+ | name | body | +----------+------------------------------------------------------------------------+ | about_us | <h1>About Us</h1> ACME Toys has been established in 1850 to provide toys | to children all over the world +----------+------------------------------------------------------------------------+ 1 row in set (0.00 sec) ---------------------------------------------------------------------- */ $result = mysql_query($sql) or die(mysql_error() ); // If the page is not found, redirect to a static page if(mysql_num_rows($result) == 0 ) { header("Location: page_not_found.html"); } $row = mysql_fetch_assoc( $result ); $body = stripslashes( $row["body"] ); // Include the header include("c:/wamp/www/exemples/header.php"); // Print the body of the page echo $body; // Include the footer include("c:/wamp/www/exemples/footer.php"); ?> --------------------CODE FOR MAIN PAGE END------------------- |