PHP - Php And Mysqli Show Colums
I hope this entry finds everyone safe and healthy. I am trying to extract table data and schema info from a database WITHOUT knowing the field names. Essentially, I want to connect to the database and have the information for each table deposited into an HTML format (just like I'd see if I accessed the db directly). I've found several methods online, but all use DEPRICATED coding that will no longer function. Any code or links to assist in resolution would be appreciated. Stay safe, and thank you. Similar TutorialsI am trying to get the output for a mysql query to be displayed in colums. I have it where it does this but it goes from left to right. I would rather it go from top to bottem, it would look better this way. I will also need it to brake into sevral pages when there are a certain amout of entrys shown. If you know of a good how to on that let me know please. The other problom that I am having is to make the output a link. I was able to do this before I attemped to devide everything but if I add in what I had before it comes back with no data. Here's what I have now that put shows the data from left to right in 2 colums. Code: [Select] <?php include"scripts/connect.php" ; mysql_connect(localhost,$username,$password); @mysql_select_db($database) or die( "Unable to select database"); $query="SELECT * FROM movies WHERE type LIKE 'movie' ORDER BY title"; if(mysql_query($query)) { $result=mysql_query($query); $num=mysql_numrows($result); } for($i=0; $i<$num; $i++) { if($i%2==0){ echo "<tr><td>"; } else{ echo "<td>"; } print mysql_result($result,$i,"title"); if ($i%2==0){ echo "</td>"; } else{ echo "</td>"; } } echo "</tr>"; ?> Thanks in advance I Have a page that will display the data that was posted into a database, but it displays it like this: id logoname locationname address city state zip phone website etc... I want to display the data like this: id <--- this will repeat records 4 columns across logoname locationname etc... id <--- this will repeat records 4 columns across logoname locationname etc... and then repeat similar for the rest of the data. Sorry Im a n00b, but trying. Here is the current code: <?php include "config.php"; $con = mysql_connect("$dbhost","$dbusr","$dbpass"); if (!$con) { die('Could not connect:'. mysql_error()); } mysql_select_db("$dbname",$con); $q="select * from venues"; $result=mysql_query($q); if (!$result) { die("Query to show fields from table failed"); } $fields_num = mysql_num_fields($result); echo "<table border='0'><tr>"; for($i=0; $i<$fields_num; $i++) { $field = mysql_fetch_field($result); echo "<td></td>"; } echo "</tr>\n"; while($row = mysql_fetch_row($result)) { echo "<tr>"; foreach($row as $cell) echo "<td>$cell</td>"; echo "</tr>\n"; } mysql_free_result($result); ?> Help would be greatly appreciated and an explanation so that I don't have to keep asking This topic has been moved to Third Party PHP Scripts. http://www.phpfreaks.com/forums/index.php?topic=313547.0 Hello I have a custom php cart working great, with product pages and shopping cart and checkout using points rather than money. My problem is that I cannot get the actual product pages to display in colums (I want 5 items per colum and 8 rows per page). Instead the whole thing is displayed as a row. Here is the page that the products are shown on: http://www.theskinnyminnie.com/user/rent/ (I have removed the need to be signed on) Here is the code I am using: Code: [Select] <?php // Run a select query to get myproducts $dynamic List =""; $sql = mysql_query("SELECT * FROM Products ORDERY BY date_added DESC"); $productCount = mysql_num_rows($sql)){ if(productCount > 0){ while($row = mysql_fetch_array($sql)){ $id = $row["product_id"]; $product_name = $row["product_name"]; $price = $row["credits"]; $date_added = strftime("%b %d, %Y", strtotime($row["date_added"])); $dynamicList .= '<tr> <td><a href="product.php?id=' . $id . '"><img src="inventory_images/' . $id . '.jpg" alt="' . $product_name . '" width="77" height="102" border="1" /></a></td></tr> <tr> <td><a href="product.php?id=' . $id . '">' . $product_name . '</a></td> </tr> <tr> <td>' . $price . 'pts</td> </tr> <tr> <td> </td> </tr>'; } } else { $dynamicList = "We have no products listed in our store yet"; } mysql_close(); ?> and then i echo dynamicList I have been working on a way to split my data into 2 columns as a way to make the page shorter and easier to read. I have been able get it to split like this 1 2 3 4 5 6 But I would rather it go like this, because it would be easier on the eyes. 1 4 2 5 3 6 This is what I have now, I have no idea if I'm even on the right track. Code: [Select] <?php include"scripts/connect.php" ; mysql_connect('localhost',$username,$password); @mysql_select_db($database) or die( "Unable to select database"); $query="SELECT * FROM movies WHERE type LIKE 'tv' ORDER BY title"; $result=mysql_query($query); $num=mysql_numrows($result); mysql_close(); ?> <table width="70%" align="left"> <?php $i=0; while ($i < $num/2) { $title=mysql_result($result,$i,"title"); ?> <tr> <td><a class="nav" href=/show.php?title=<?php echo urlencode($title); ?>><?php echo $title; ?></td> <?php while ($i >= $num/2) { ?> <td><a class="nav" href=/show.php?title=<?php echo urlencode($title); ?>><?php echo $title; ?></td> </tr> <?php } $i++; } ?> </table> This will show only the first half of the titles. Thanks in advance. hello, normally when i query mysql, it returns my results line by line. im trying to make a print view now that will put 3 results in a row before going to the next row. any help appreciated. What I am trying to do is create a search box to search for a specific piece of information in my client database, say last name, or account number, invoice number, etc. is there a way i can use the keyword to match the query to multiple columns? here is my code, the script works if i use the $query to select just 1 column. but how do i add other columns to match it to? I know its where "different columns" LIKE search my problem is this line basically. Code: [Select] mysql_select_db("terra_elegante_operations", $con); $searchfor = $_GET['search_term']; $query = "select * from client_information where name_last like \"%$searchfor%\""; $result = mysql_query($query) or die("Couldn't execute query"); $row = mysql_fetch_array($result); echo $row['0']; I am using the following code to generate a dynamic drop down menu from a column in table1(name) - and then inserting the selected option into table2. What I am trying to do is, select data from 2 columns from table1(name,age) and then store and insert both of those values into table2 I am hoping someone can help me out or at least point me in the rigth direction. ..I would like to insert into table 2 the age that matches the person selected by the drop down menu from table1. For example - if from the drop down menu I choose John - when the form is sumbitted i want to insert into table2 John's name and age (based on what is stored in table1, in this case John,22) ...Any ideas??? table1 id|name|age|score 01-john-22-1547 02-jane-22-1245 table2 id|county|name|age the dynamic drop down is generated from table1 (name) with following code Code: [Select] <form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>"> <table width="100%" border="0" cellpadding="5" cellspacing="0"> <?php require_once('sql.php'); $dbc = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME); $query="SELECT name FROM table1 ORDER BY name ASC"; $result = mysqli_query ($dbc,$query) or die(mysqli_error()); $dropdown = "<select name='name'>"; while($row = mysqli_fetch_array($result)) { $dropdown .= "\r\n<option value='{$row['name']}'>{$row['name']}</option>"; } $dropdown .= "\r\n</select>"; echo $dropdown; ?> <tr> <td height="50" align="right"> <label for="scheduled_time">Country</label><br/> </td> <td align="left"> <input type="text" id="country" name="country" class="input" maxlength="30"" /> </td> </table> <p></p> <input type="submit" value="Add Info" name="submit" /> </form> I am inserting into table2 with the following code Code: [Select] <?php $dbc = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME); if (isset($_POST['submit'])) { $county = mysqli_real_escape_string($dbc, trim($_POST['country'])); $name = mysqli_real_escape_string($dbc, trim($_POST['name'])); $query = "INSERT INTO table2 (country, name) VALUES ('$country', '$name'')"; $result = mysqli_query($dbc, $query); if (!$result) { printf("query error : <br/> %s\n", mysqli_error($dbc)); } if ($result) { echo 'Success'; } // close dbc mysqli_close($dbc); exit(); } ?> I am pulling some info from a mysql table, checking some logic, and displaying in on a page. The way this is written now it shows all of the items in a one column table, I simply want to break it up into multiple columns (ideally by specifying say 20 items per column). I know I need a counter and a loop but I'm just not sure how it all fits in with my existing program. Any help would be greatly appreciated. Here is my code Code: [Select] $result2 = mysql_query("SELECT * FROM propertyids ORDER BY propertyname ASC"); while($row2 = mysql_fetch_array($result2)){ ${'resp'.$row2['id']} = curl_multi_getcontent(${'ch'.$row2['id']}); ${'status'.$row2['id']} = strpos(${'resp'.$row2['id']},$httpvar); if(${'status'.$row2['id']} === false) { echo "<tr><td>"; echo "<img src='images/down.png'> <a href='" . $row2['primaryurl'] . "' target='_blank'>" . $row2['propertyname'] . "</a>"; echo "</td></tr>"; } else { echo "<tr><td>"; echo "<img src='images/up.png'> <a href='" . $row2['primaryurl'] . "' target='_blank'>" . $row2['propertyname'] . "</a>"; echo "</td></tr>"; } } echo "</td></table>"; hirealimo.com.au/code1.php this works as i want it: Quote SELECT * FROM price INNER JOIN vehicle USING (vehicleID) WHERE vehicle.passengers >= 1 AND price.townID = 1 AND price.eventID = 1 but apparelty selecting * is not a good thing???? but if I do this: Quote SELECT priceID, price FROM price INNER JOIN vehicle....etc it works but i lose the info from the vehicle table. but how do i make this work: Quote SELECT priceID, price, type, description, passengers FROM price INNER JOIN vehicle....etc so that i am specifiying which colums from which tables to query?? thanks I want to show a cookie of a referral's username on a sign up page. The link is like this, www.mysite.com/signup?ref=johnsmith. The cookie doesn't show if I go to that url page. But it does show up once I reload the page. So I'm wondering if it's possible to show the cookie the first time around, instead of reloading the page? Here is my code. // This is in the header $url_ref_name = (!empty($_GET['ref']) ? $_GET['ref'] : null); if(!empty($url_ref_name)) { $number_of_days = 365; $date_of_expiry = time() + 60 * 60 * 24 * $number_of_days; setcookie( "ref", $url_ref_name, $date_of_expiry,"/"); } else if(empty($url_ref_name)) { if(isset($_COOKIE['ref'])) { $user_cookie = $_COOKIE['ref']; } } else {} // This is for the sign up form if(isset($_COOKIE['ref'])) { $user_cookie = $_COOKIE['ref']; ?> <fieldset> <label>Referred By</label> <div id="ref-one"><span><?php if(!empty($user_cookie)){echo $user_cookie;} ?></span></div> <input type="hidden" name="ref" value="<?php if(!empty($user_cookie)){echo $user_cookie;} ?>" maxlength="20" placeholder="Referrer's username" readonly onfocus="this.removeAttribute('readonly');" /> </fieldset> <?php }
I am displaying rows from a database onto a page using: while($row=mysql_fetch_array($query)){ echo $row['name']; } I need to figure out how to limit the rows shown to the page to 100. And if there are 100 rows on the page, a link will be displayed at the bottom, that says "Next 100". Then this will display the next 100 rows. Can you give an example how to do this please? Thanks hello , I'm starting to use mysqli and i have few questions. is there a guide for mysqli? and how do i use this functions at mysqli ? mysql_num_rows mysql_query mysql_fetch_assoc mysql_fetch_array thanks , Mor. I am using mysqli, OO, to connect to MySQL. I have only today started looking at this and am used to: Code: [Select] <?php $con = mysql_connect();//etc mysql_close($connection); ?> Am I right that with mysqli (OO) that I don't need to set a connection variable wither when connecting or closing?? Code: [Select] <?php mysqli::connect();//etc mysqli::close(); ?> What about with multiple databases, does mysqli keep track for me, as I am used to this: Code: [Select] <?php $con1 = mysql_connect();//db1 $con2 = mysql_connect();//db2 ?> //etc I dont know whether the statement is correct.....i just tried it.....and it didn't work. $stmt->bind_param('ssiiiss',$_POST['name'],$_POST['email'],$_POST['d'],$_POST['m'],$_POST['y'],$_POST['add'],$_POST['phone']); here my first two values are strings and next 2 tiny int's next is int and last 2 again strings.
The below code produces a dropdown and when a selection is made and submitted produces --------------------------------------------------------------------------- <!DOCTYPE><html><head> <title>lookup menu</title> </head> <body><center><b> <form name="form" method="post" action=""> <?php // error_reporting(0); error_reporting(E_ALL ^ E_NOTICE); include 'homedb-connect.php'; //This creates the drop down box echo "<select name= 'target'>"; echo '<option value="">'.'--- Select account ---'.'</option>'; $query = mysqli_query($con,"SELECT target FROM lookuptbl"); $query_display = mysqli_query($con,"SELECT * FROM lookuptbl"); while($row=mysqli_fetch_array($query)) {echo "<option value='". $row['target']."'>".$row['target'] .'</option>';} echo '</select>'; ?> <input type="submit" name="submit" value="Submit"/> </form><center> <?php // error_reporting(0); error_reporting(E_ALL ^ E_NOTICE); include 'homedb-connect.php'; if(isset($_POST['target'])) { $name = $_POST['target']; $fetch="SELECT target, purpose, user, password, email, visits, date, saved FROM lookuptbl WHERE target = '".$name."'"; $result = mysqli_query($con,$fetch); if(!$result) {echo "Error:".(mysqli_error($con));} //display the table echo '<table border="1"><tr><td bgcolor="#ccffff" align="center">lookup menu</td></tr> <tr><td> <table border="1"> <tr> <td> Target </td> <td> Purpose </td> <td> User </td> <td> Password </td> <td> Email </td> <td> Visits </td> <td> Date </td> <td> Saved </td> </tr>'; while($data=mysqli_fetch_row($result)) { $url= "http://localhost/home/crud-link.php?target=". $data[0]; $link= '<a href="'.$url.'">'. $data[0]. '</a>'; echo ("<tr><td> $link </td><td>$data[1]</td><td>$data[2]</td><td>$data[3]</td> <td>$data[4]</td><td>$data[5]</td><td>$data[6]</td><td>$data[7]</td></tr>"); } echo '</table> </td></tr></table>'; } ?> </body></html>
Hello everyone, For two weeks now, I'm trying to get this database connection in my query. Can someone give me a solution and tell me what I've done wrong? Am I overlooking something? <?php class Mysql{ public function connect(){ $mysqli = new mysqli('localhost','root','','login'); } } class Query extends Mysql{ public function runQuery(){ $this->result = parent::connect()->query("select bla bla from bla bla"); } } $query = new Query; $query->runQuery(); ?> When running the following code i get the error: Call to undefined method mysqli::errno() the code: $conn = new mysqli(HOST, USER, PASSWORD, DATABASE); if ($conn->errno() !== 0) { $msg = $conn->error(); throw new connErrorException($msg, 'Connect'); } I am fairly new to classes but as i understand it this should be correct. I am using mysql 5.1 so mysqli is on by default. I have even checked the php ini and everything looks fine there in respect to this. Any advice? Ok I am trying to use mysqli instead of the usual mysql. Mysql would be outdated. With mysqli, sgl-injection is impossible if you use the "?" in those codes. I would normally use a function but I've made a simple script to find the error. I use $parameters and $sql because these are the data I need to give as parameters to the function, so I used it here too but without the function actually. Code: [Select] ini_set('display_errors',1); // 1 == aan , 0 == uit error_reporting(E_ALL | E_STRICT); # sql debug define('DEBUG_MODE',true); // true == aan, false == uit $userid = 11; $lang = 1; $newLink = "testing123"; $db_host = "localhost"; $db_gebruiker = "root"; $db_wachtwoord = ''; $db_naam = "projecteasywebsite"; $sql= "INSERT tbl_link(userid,linkcat,linksubid,linklang,linkactive,linktitle) VALUES(?, ?, ?, ?, ?, ?)"; $parameters = '"iiisis", $userid, 1, 0, $lang, 1, $newLink'; echo $parameters; $mysqli = new mysqli($db_host, $db_gebruiker, $db_wachtwoord, $db_naam); $stmt = $mysqli->prepare($sql); $stmt->bind_param($parameters); $stmt->execute(); echo "<br><br>". mysqli_connect_errno(); echo "<br><br>". mysqli_report(MYSQLI_REPORT_ERROR); $stmt->close(); $mysqli->close(); I got Wrong parameter count for mysqli_stmt::bind_param() So naturally a problem when we execute : Warning: mysqli_stmt::execute() [mysqli-stmt.execute]: (HY000/2031): No data supplied for parameters in prepared statement ($stmt->execute() Is someone using mysqli too ? I have just started using MySQLi and am clueless it is giving me the follow errors in which i do not understand
Warning: mysqli_select_db() expects exactly 2 parameters, 1 given in C:\xampp\htdocs\Login\connect.php on line 23 Notice: Trying to get property of non-object in C:\xampp\htdocs\Login\connect.php on line 25 Notice: Use of undefined constant mysqli - assumed 'mysqli' in C:\xampp\htdocs\Login\connect.php on line 32 Warning: mysqli_query() expects parameter 1 to be mysqli, string given in C:\xampp\htdocs\Login\connect.php on line 32 Warning: mysql_fetch_assoc() expects parameter 1 to be resource, null given in C:\xampp\htdocs\Login\connect.php on line 33 can someone please explain to me why i am getting these? and my code is $mysqli_db = mysqli_select_db("$db_name"); if($mysqli_db->connect_errno) { printf("Database not found: %s\n", $mysql->connect_error); exit(); } $sql = "SELECT * FROM $tbl_name WHERE username='$username' AND password='$password'"; $result = mysqli_query($sql); $row = mysqli_fetch_assoc($result);I just got rid off most the errors the only ones left are Warning: mysqli_query() expects at least 2 parameters, 1 given in C:\xampp\htdocs\Login\connect.php on line 32 Fatal error: Call to undefined function mysqli_result() in C:\xampp\htdocs\Login\connect.php on line 33 Code Updated: $mysqli_db = mysqli_select_db($mysqli_connect, $db_name); if(!$mysqli_db) { printf("Database not found: %s\n", $mysqli->connect_error); exit(); } $sql = "SELECT * FROM $tbl_name WHERE username='$username' AND password='$password'"; $query = mysqli_query($sql); $result = mysqli_result($query); $row = mysqli_fetch_assoc($result); Edited by Tom8001, 30 November 2014 - 12:43 PM. |