PHP - Include Mysql Numrows
How do I find the count of mysql num rows and output that value with this function?
Code: [Select] function fetch_company_fans($cid) { $cid = (int)$cid; $sql = "stuff"; $result = mysql_query($sql); $fans = array(); while (($row = mysql_fetch_assoc($result)) !== false) { $fans[] = array( 'username' => $row['username'], ); } return $fans; } Similar TutorialsHi all, I'm wondering if it's possible to use the $numrows boolean parameter where $numrows = 0 and meets a condition. For instance, my code is set up to check for classes where $numrows>0 and then displays the classes. If $numrows < 1, it echoes a message saying there are no classes available and to call the training department. I would like to redirect one of the classes to another link by using a strpos function to search for the classname within the URL. As I understand it, I would have to embed it in the else part of the statement if it's at all possible. Here's what I have so far. if ($numrows > 0) { echo "<p align=\"left\" class=\"style2 style4\">Click in the check box next to the date for which you would like to register: </p>"; echo "<p align=\"left\" class=\"style2 style4\">" . $_GET['classname'] . "</p>"; echo "<table width=100% style=\"color:#FFFFFF\">"; echo "<th></th>"; echo "<th>Date</th>"; echo "<th>Time</th>"; echo "<th>Location</th>"; echo "<th>Instructor</th>"; while ($results = mysql_fetch_array($rs)){ echo "<tr>"; echo "<td><input type=\"radio\" name=\"checkbox\" value=\"" . $results['date'] . "|" . $results['time'] . "|" . $results['location'] . "|" . $results['instructor'] . "|" . $results['course'] . "\"" . "></td>"; echo "<td class=\"style11\">" . $results['date'] . "</td>"; echo "<td class=\"style11\">" . $results['time'] . "</td>"; echo "<td class=\"style11\">" . $results['location'] . "</td>"; echo "<td class=\"style11\">" . $results['instructor'] . "</td>"; echo "</tr>"; } echo "</table>"; } elseif (strpos($_REQUEST['classname'], "BloodBorne Pathogens Video")); { echo "Bloodborne Pathogens is exclusively offered online. Please <a href=../training/online_courses/Bloodborne/BB.html>click here</a> to take the course."; } else { echo "Please call the training department as there are no classes scheduled at this time." } Please let me know if this is even possible or if I'm off my rocker. I'm fairly new to the PHP world but not a newb Thanks a bunch for your time! Hi All, pls help me with this I have include a 'connect.php' but it resulted error "mysql_fetch_array() expects parameter 1 to be resource, boolean given in C:\wamp\www\carpark\viewcars.php on line 21" but if I dont use php include then everything works fine,,, below the code : <?php include "connect.php"; echo "<table border='1' id='position'> <tr> <th>Ticket</th> <th>Car Name</th> <th>Car Out</th> </tr>"; $result=mysql_query("select * from car"); while ($row=mysql_fetch_array($result)) { echo "<tr>"; echo "<td>".$row['ticket']."</td>"; echo "<td>".$row['carname']."</td>"; echo "</tr>"; } echo "</table>"; mysql_close(); ?> connect.php <? $host="localhost"; $user="root"; $password=""; mysql_connect($host,$user,$password); mysql_select_db("car"); ?> If I use below ,,everything works fine ... what went wrong ??? <? $host="localhost"; $user="root"; $password=""; mysql_connect($host,$user,$password); mysql_select_db("car"); echo "<table border='1' id='position'> <tr> <th>Ticket</th> <th>Car Name</th> <th>Car Out</th> </tr>"; $result=mysql_query("select * from car"); while ($row=mysql_fetch_array($result)) { echo "<tr>"; echo "<td>".$row['ticket']."</td>"; echo "<td>".$row['carname']."</td>"; echo "</tr>"; } echo "</table>"; mysql_close(); ?> I am trying to insert a record into a mysql database which has a $ as part of the value of a field. But it seems that when the INSERT query is processed its actually looking for a variable with that name and not just inserting the raw text. Here is the insert query $query = "INSERT mytable SET myfield='I would like to have this field contain this information with a $matches[1] showing in the field value as well'"; $matches[1] has no value. Its not a variable which is in this script. I am not trying to insert the value of it. I just want to insert the actual text characters $matches[1] How can I do that? Hi, This is an odd one (to me anyway). I've created an API for deploying gig information in either XML or JSON format. It works fine as it is, both formats of output giving me what I want. When I take out the mySQL login information and replace it with "include 'connect_include.php';" (where the file connect_include.php contains the exact login code that I replced). The JSON output works fine but the XML output doesn't run. What could be causing this?? JSON API: -http://www.api.the-guards.co.uk/jsontest.php?apikey=123456&format=json XML API: - http://www.api.the-guards.co.uk/jsontest.php?apikey=123456&format=xml API code: Code: [Select] <?php if (($_GET['apikey'])==123456 and isset($_GET['format'])){ //Set variables $format = strtolower($_GET['format']); //Connect to the Database include 'connect_include.php'; //Run our query $result = mysql_query(' SELECT * FROM tg_gig_list where gl_date >= curdate() and gl_publish = 1 order by gl_date '); //Preapre our output if($format == 'json') { while ($row = mysql_fetch_array($result,MYSQL_ASSOC)) { $array[] = array($row['gl_date']=>($row['gl_venue'].', '.$row['gl_city'])); }; $output = json_encode($array); //Output the output. echo $output; header('Content-type: application/json'); } elseif($format == 'xml') { header('Content-type: text/xml'); $output = "<?xml version=\"1.0\"?>\n"; $output .= "<tggiglist>\n"; for($i = 0 ; $i < mysql_num_rows($result) ; $i++){ $row = mysql_fetch_assoc($result); $output .= "<giglist> \n"; $output .= "<giglist_date>" . $row['gl_date'] . "</giglist_date> \n"; $output .= "<giglist_venue>" . $row['gl_venue'] . "</giglist_venue> \n"; $output .= "<giglist_city>" . $row['gl_city'] . "</giglist_city> \n"; $output .= "</giglist> \n"; } $output .= "</tggiglist>"; } } else { die ('no way'); } //output the output echo $output; ?> Contents of 'connect_include.php: Code: [Select] <?php mysql_connect("database.lcn.com", "dbname", "password") or die(mysql_error()); mysql_select_db("db") or die(mysql_error()); ?> .....this is the same code that I replaced. Obviously, the 'connect' works ok as the JSON version runs fine. There's something being added to the scripting when I use the include file that isn't there when the code goes straight in.....I think???? I've a simple Inset List (jQuery Mobile) of several items with a Flip switch, Drop down, check box and Slider elements. I have wrapped this Inset List inside a HTML Form. <code> <div data-role="fieldcontain"> <ul data-role="listview" data-inset="true"> <li data-role="list-divider"> Inhouse capabilities </li> <li> <label for="flip-b">Project Manager</label> <select name="slider" id="flip-b" data-role="slider"> <option value="no">No</option> <option value="yes">Yes</option> </select> </li> <li> <label for="flip-b">Site Supervisor</label> <select name="slider" id="flip-b" data-role="slider"> <option value="no">No</option> <option value="yes">Yes</option> </select> </li> <li><label for="flip-b">Architect</label> <select name="slider" id="flip-b" data-role="slider"> <option value="no">No</option> <option value="yes">Yes</option> </select> </li> <li><label for="flip-b">Builderworks</label> <select name="slider" id="flip-b" data-role="slider"> <option value="no">No</option> <option value="yes">Yes</option> </select> </li> <li><label for="flip-b">Electrical</label> <select name="slider" id="flip-b" data-role="slider"> <option value="no">No</option> <option value="yes">Yes</option> </select> </li> <li><label for="flip-b">Mechanical</label> <select name="slider" id="flip-b" data-role="slider"> <option value="no">No</option> <option value="yes">Yes</option> </select> </li> <li><label for="flip-b">Hydraulics</label> <select name="slider" id="flip-b" data-role="slider"> <option value="no">No</option> <option value="yes">Yes</option> </select> </li> <li><label for="flip-b">Joinery</label> <select name="slider" id="flip-b" data-role="slider"> <option value="no">No</option> <option value="yes">Yes</option> </select> </li> <li> <label for="select-choice-1" class="select">Main Location:</label> <select name="select-choice-1" id="select-choice-1"> <option value="NSW">NSW</option> <option value="ACT">ACT</option> <option value="VIC">VIC</option> <option value="SA">SA</option> <option value="QLD">QLD</option> <option value="NT">NT</option> <option value="WA">WA</option> <option value="TAS">TAS</option> </select> </li> <!-- Select Menus: Main Location--> <li> <div data-role="fieldcontain"> <fieldset data-role="controlgroup"> <legend>CBA Reference</legend> <input type="checkbox" name="checkbox-1a" id="checkbox-1a" class="custom" /> <label for="checkbox-1a">Commercial</label> <input type="checkbox" name="checkbox-2a" id="checkbox-2a" class="custom" /> <label for="checkbox-2a">Retail</label> </fieldset> </div> </li> </ul> </div> <!-- End of Field Contain div tag --> <a href="#additionalinfo" data-role="button" data-inline="true" data-iconpos="left" data-theme="b">Additional Info</a> <a href="./search2.html" rel="external" data-ajax="false" data-role="button" data-inline="true" data-icon="search" data-iconpos="left" data-theme="e">Search</a> </code> I want to know, how I can include only the elements the user selected in my SQL query. Lets say, User wants to find the Electrical workers in QLD, then he will select Yes for Electrical and QLD as Main Location and the other items he would not touch. Now, how can I include only those two values in the select clause. Say, Select Electrical, Main Location from table where Main location='QLD'. I used POST method to gather users input. I use PHP, MySQL for this project. Any ideas on how to achieve this. Regards Sandeep CanI put one INCLUDE statement INSIDE of another INCLUDE statement? Hi Still a new comer when it comes to PHP. I have a situation where I want to use an include within an include and I am having trouble with my file paths. My main header include, includes everything for each page of my site, beyond the opening of the body to incorporate my navigation etc conditionally loading in css, and loading in titles and meta data etc depending on the page in question. This header needs to reference another include called the-pod.php which is required for every page, the only trouble is I want to use / to reference the root of the server and this is breaking my code. I can't use ../../ etc as its a different path depending on where the master file is located. So my question is how do I get around this? Can the root of the server or path to the root be stored in a variable? and if so how would I write this. Any tips / advice will be greatly appreciated. Hi Guys.. Merry Christmas Im kinda new to this fantastic world of PHP and i have a little problem i hope you can help me with. Im trying to build a website where I use include() to genereate my content. On my index.php i have a menu which includes content in a content div from external .php pages, my structure kinda goes like this.. (simplified) site/ index.php content/ fronpage.php products.php contact.php The HTML looks like this. <div id="menu"> <ul> <li><a href="index.php?page=frontpage">frontpage</a></li> <li><a href="index.php?page=products">frontpage</a></li> <li><a href="index.php?page=contact">frontpage</a></li> </ul> </div <div id="main"> <?php include('/content/'.$_GET['page'].'.php'); ?> </div> This all works very fine, but my problem is, can I have a include inside an already included page? I would like to have a menu on my products.php site, but that page is already included from above, and i would like the menu on the products.php site to stay as the content from the nested include changes with input from the /products folder. my idea was something like this. site/ index.php content/ frontpage.php products.php contact.php products/ product1.php product2.php the HTML on the index.php is the same as above and then i would add the include() on the products.php page, so its kinda the same thing, but one inside the other. HTML inside the products.php folder <div id="sub_menu"> <ul> <li><a href="#">frontpage</a></li> <li><a href="#">frontpage</a></li> <li><a href="#">frontpage</a></li> </ul> </div <div id="sub_main"> <?php include('/content/products'.$_GET['#'].'.php'); ?> </div> I dont know how to link to the new files so they will be included while the first include still stays on the page. Any of you know how and if this can be done? Or maybe at better way to do it? Hope this made sense, my first PHP question Thanks When I put this above all else in my document and test it offline, all I see is code in the browser. But when I test it on my web server, I can view the markup and whatnot. Does anyone know why this is? Hello, I created a script at my server, but would like to upload files to my other server. The website runs on server 1 and the upload form on server 2. I want to include the file of server 2 at the page at server 1; I've tried: include("http://ipaddress/upload.php"); Sadly, this doesn't work. I get the error: Quote URL file-access is disabled in the server configuration in Is there another way to do it? Or should I change the php.ini and allow this (why isn't it allowed by default? What are the risks?). iFrames aren't what I need here. Thanks, NLCJ Hi I have recently moved hosting providers; I have a php include on my website, which feeds latest posts from my forums to my homepage. The code I use is <?php include ('../mb/getposts/posts.php?id=80')?> Now, this code used to work on my old host, but no longer works on my new host, giving an error of Code: [Select] Warning: include(../mb/getposts/posts.php?id=80) [function.include]: failed to open stream: No such file or directory in /home/site/public_html/folder/page.php on line 41 Warning: include(../mb/getposts/posts.php?id=80) [function.include]: failed to open stream: No such file or directory in /home/site/public_html/folder/page.php on line 41 Warning: include() [function.include]: Failed opening '../mb/getposts/posts.php?id=80' for inclusion (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/site/public_html/folder/page.php on line 41 I can also include the script as <?php include ('../mb/getposts/posts.php')?> and when I do this the script works as it should do, but showing the default option. The ?id=xx bit allows me to choose what forum id I want the posts to be shown on my homepage as I have lots of individual homepages (long story) and to try and keep files small, I decided to wrap the latest posts php file into something where i could use one file for all the forums IDs that I need to show Does anyone know why this will not work? I am thinking it's a problem with the php config of my new server, and have asked my hosts, but they are telling me that this is out of their scope of support.. Any ideas would be appreciated Okay if I use an include to include a login script the login button doesn't work at all but it works on the page itself just not on the include http://store.crytell.com/ when I attempt to login nothing happens Im sure I have the script dir right Code: [Select] <body bgcolor="#100f14"> <? /** * Main.php * * This is an example of the main page of a website. Here * users will be able to login. However, like on most sites * the login form doesn't just have to be on the main page, * but re-appear on subsequent pages, depending on whether * the user has logged in or not. * * Written by: Jpmaster77 a.k.a. The Grandmaster of C++ (GMC) * Last Updated: August 26, 2004 */ include("./storelogin/include/session.php"); ?> <html> <title>Jpmaster77's Login Script</title> <body> <table> <tr><td> <? /** * User has already logged in, so display relavent links, including * a link to the admin center if the user is an administrator. */ if($session->logged_in){ echo "<h1>Logged In</h1>"; echo "Welcome <b>$session->username</b>, you are logged in. <br><br>" ."[<a href=\"./storelogin/userinfo.php?user=$session->username\">My Account</a>] " ."[<a href=\"./storelogin/useredit.php\">Edit Account</a>] "; if($session->isAdmin()){ echo "[<a href=\"./storelogin/admin/admin.php\">Admin Center</a>] "; } echo "[<a href=\"./storelogin/process.php\">Logout</a>]"; } else{ ?> <h1>Login</h1> <? /** * User not logged in, display the login form. * If user has already tried to login, but errors were * found, display the total number of errors. * If errors occurred, they will be displayed. */ if($form->num_errors > 0){ echo "<font size=\"2\" color=\"#ff0000\">".$form->num_errors." error(s) found</font>"; } ?> <form action="./storelogin/process.php" method="POST"> <table align="left" border="0" cellspacing="0" cellpadding="3"> <tr><td>Username:</td><td><input type="text" name="user" maxlength="30" value="<? echo $form->value("user"); ?>"></td><td><? echo $form->error("user"); ?></td></tr> <tr><td>Password:</td><td><input type="password" name="pass" maxlength="30" value="<? echo $form->value("pass"); ?>"></td><td><? echo $form->error("pass"); ?></td></tr> <tr><td colspan="2" align="left"><input type="checkbox" name="remember" <? if($form->value("remember") != ""){ echo "checked"; } ?>> <font size="2">Remember me next time <input type="hidden" name="sublogin" value="1"> <input type="submit" value="Login"></td></tr> <tr><td colspan="2" align="left"><br><font size="2">[<a href="./storelogin/forgotpass.php">Forgot Password?</a>]</font></td><td align="right"></td></tr> <tr><td colspan="2" align="left"><br>Not registered? <a href="./storelogin/register.php">Sign-Up!</a></td></tr> </table> </form> <? } /** * Just a little page footer, tells how many registered members * there are, how many users currently logged in and viewing site, * and how many guests viewing site. Active users are displayed, * with link to their user information. */ echo "</td></tr><tr><td align=\"center\"><br><br>"; echo "<b>Member Total:</b> ".$database->getNumMembers()."<br>"; echo "There are $database->num_active_users registered members and "; echo "$database->num_active_guests guests viewing the site.<br><br>"; include("./storelogin/include/view_active.php"); ?> </td></tr> </table> </body> </html> Code: [Select] <?include_once "./storelogin/main.php"; // this will include a.php?> I have to store my Authorize.net Payment Gateway values somewhere safe. (i.e. Outside of the Web Root) I tried this code but my checkout page that formerly worked with local values in Test Mode is crashing. // Include Authorize.net Values. require_once('/var/www/vhosts/MyWebsite.com/private/auth_config.php'); I think the issue is that private maybe can't be read or included by other files? Would using another Linux directory solve my problem? Debbie Dear All, I have just signed up to the forums so hello. I'm a complete novice to PHP and have a question. I've written a site using PHP but am stuck, how I have written is that certain pages use INCLUDE files that pull out information from .TXT files. The question I have is, is it possible to contain another INCLUDE link within the .TXT file? i.e. index.php includes companyname.txt but companyname.txt only has this line of text in it: <?php include("../includes/moreinformation.txt"); ?> I know it is quite a weird question/request but is there a way of doing this? So basically have an include within an include although the file extensions are .TXT. Thanks and looking forward to any help from you Pros. Kindest regards, James. James. I am creating several files with the same connection information. I already REQUIRE_ONCE my connection data that has all the 'secret entry data', but am wondering, if this is my current code in the top of the files: $con = require_once('connection.php'); if (!$con) { die('Could not connect!' . mysql_error()); } mysql_select_db("$database") or die('Choose a database ' . mysql_error()); And then a $query/$result Can the lines BEFORE the $query go into an INCLUDE file ALSO if they are going to be constant and repeated, or do they have to be hardcoded into each file individually? Hi, I'm so new to PHP. Kindly help me figure out on how to use include function.. situation is.. I am going to include a head.php file /includes/head.php this is the path where i want to include head.php /menu/menulist/list in "list" folder that is where I want to include head.php include works on folder "menulist" but not on 3rd folder "list" any advise on how tot solve this problem of mine? Thanks I have an include file and a php file in different directories and I can't figure out what I'm doing wrong trying to get them to relate to one another. webhost/website/includes/include.inc webhost/website/modules/module/page.php How do I get the page.php to use the include.inc file? I'd think it would be "../../include.inc", but that isn't working I am fairly new to PHP. I tried searching for answers on Google and in this forum, but I found no solutions. Problem I used PHP include as a way of navigating through my website. I did this so if I changed the design of the website, I don't have to edit each page. The function is similar to iframes. Yesterday I developed a tip calculator (calculates how much tip you need to give to the waiter or waitress based on your bill). However I've noticed after I press "submit", it sends the visitor to a page that shows only the results. I want to show the results within my website design. Screen shots: I input the data. Notice the gray background and the navigation bar. After I press "Submit Order", it shows the results but the results aren't within my website's design. (Notice the white background). Question: How can I incorporate the results from the tip calculator in my design after pressing the "Submit Order" button? Here is the code on the main page of my website (HTML/CSS with PHP) P.S For links in the navigation section, I used : ?id=name Code: [Select] <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>MV Book</title> <link href="style.css" rel="stylesheet" type="text/css" media="screen" /> </head> <body> <div id="wrapper"> <div id="wrapper2"> <div id="header"></div> <!-- End of Header --> <div id="navi"> <ul> <li><a href="/">Home</a></li> <li><a href="?id=tip">Tip calculator</a></li> <li><a href="?id=orderform">Tip calculator</a></li> </ul> </div> <!-- End of Navi --> <div id="content"> <?php $id = $_GET['id'] ; switch($id) { default: include('cutenews/show_news.php'); break; case "orderform": include('orderform.html'); break; case "tip": include('tip.php'); } ?> </div> <!-- End of Content --> </div> <!-- End of Wrapper 2 --> </div> <!-- End of Wrapper --> </body> </html> And this is the code that is on the page where I input the code: Code: [Select] <form action="processtip.php" method="POST"> <table border="0"> <tr> <td>Bill Amount</td> <td align="center"><input type="text" name="billamount" size="10" maxlength="10" id="billamount"></td> </tr> <td>Tip Percent (%)</td> <td align="center"><input type="text" name="tippercent" size="10" maxlength="10" id="tippercent"></td> </tr> <tr> <td>Number Of People (Split)</td> <td align="center"><input type="text" name="people" size="10" maxlength="10" id="people" /></td> </tr> <tr> <td colspan="2" align="center"><input type="submit" value="Submit Order"></td> </tr> </table> </form> This is the PHP Code that process the input data and displays the results (processtip.php) : Code: [Select] <?PHP $billamount = $_POST['billamount']; $tipnumber = $_POST['tipnumber']; $people = $_POST['people']; ?> <html> <head> <title>Emaj's Tip Calculator</title> </head> <body> <h1>Emaj's Tip Calculator</h1> <h2>Thanks for using my Online Tip Calculator</h2> <?php if ($billamount < 0) { echo "<p> You can't have a negative number. Does the restuarant owe you money?"; exit; } else { if ($billamount == 0) { echo "What's the point of using a tip calculator if you didn't order anything?<br />"; exit; } if ($billamount > 0) { echo "<p> Your bill is $".$billamount; } } $tippercent = 0; $tippercent = $tipnumber/100; $tipamount = 0; $tipamount = $billamount * $tippercent; echo "<p> Total tip is $".$tipamount; $totalamount = 0; $totalamount = $billamount + $tipamount; echo "<p>Total bill (Tip included) is $".$totalamount; echo "<p>You are splitting the Total Bill with ".$people." people."; $indperson = 0; $indperson = $totalamount/$people; echo "<p>Each individual person pays $".$indperson; ?> If there is a thread that has a similar problem with a solution, can you please post a link to it? Thank you and I apologize in advance if there's a duplicate thread. -Emaj Hi, is there any way to clear the included file in php? for example, if i included a file like , include "file.php"; after using the functions in this file finally i want to exclude from the list. I have a script that is going to be on several urls. There is a master site that will have certain information that will need to be present on all urls that host this script. I am planning on using RSS to do this. What is a good method to dynamically create the xml file for the master site so that the feed can be broadcast to the other urls? Thanks in advance for the input. |