Search the Community
Showing results for tags 'mysql'.
-
I always get confused on this part. I am playing with a mySql Maria DB. in my localhost PC.... ohhh am using PDO Am I just checking for "0" failure and "1" Success return? some extra code to see how many rows effected .. in DB2 a return code of 100, meant no records were found but it was a successful execution. What kinda things do i need to check for? do the all return a code? What is the DB goes down? will my query return a code? or will it fail in another place? Besides a down DB what else must i look for? Thanks
-
How do I style this table to make it look "prettier" I have tried a little with css and html tags with no luck. // display data in table echo "<table border='1' cellpadding='10'>"; echo "<tr> <th>ID</th> <th>First Name</th><th>Middle Name</th> <th>Last Name</th><th>Client ID</th><th>Diagnosis</th><th>Gender</th><th>Level of Care</th><th>Counselor</th><th>Active</th><th>Aftercare</th></tr>"; // loop through results of database query, displaying them in the table for ($i = $start; $i < $end; $i++) { // make sure that PHP doesn't try to show results that don't exist if ($i == $total_results) { break; } // find specific row $result->data_seek($i); $row = $result->fetch_row(); // echo out the contents of each row into a table echo "<tr>"; echo '<td>' . $row[0] . '</td>'; echo '<td>' . $row[3] . '</td>'; echo '<td>' . $row[1] . '</td>'; echo '<td>' . $row[2] . '</td>'; echo '<td>' . $row[4] . '</td>'; echo '<td>' . $row[5] . '</td>'; echo '<td>' . $row[7] . '</td>'; echo '<td>' . $row[10] . '</td>'; echo '<td>' . $row[11] . '</td>'; echo '<td>' . $row[15] . '</td>'; echo '<td>' . $row[18] . '</td>'; echo '<td><a href="records.php?id=' . $row[0] . '">Edit</a></td>'; echo '<td><a href="delete.php?id=' . $row[0] . '">Delete</a></td>'; echo "</tr>"; } // close table> echo "</table>";
-
Hello, After following along and successfully completing Ben's tutorial of the Online Shopping Cart, I figured I would try and make my own. The first major problem I am having is being able to display my products from my database in my index.php page. The goal is to actually see the images of each product displayed in index.php (like in the tutorial). This would then enable me to add my products to the cart.php page. I've checked the database connection and it does exist. My guess would be that I am using the wrong syntax to display my products in the "fetch_all_products()" method. *** M_PRODUCTS.PHP *** <?php class Products { private $Conn; private $db_table = "toys"; function __construct() { // here we're making sure that the connection from $conn in "init.php" is transferred // into our own private $conn property for usage in this object global $Conn; $this->Conn = $Conn; } // fetches and displays all products from db public function fetch_all_products($id = NULL) { if ($id = NULL) { $data = "<li>"; if ($result = $this->conn->query("SELECT * FROM " . $this->db_table . " ORDER BY name")) { if ($result->num_rows > 0) { while ($row = $result->fetch_array()) { $data .= array( "id" => $row["product_id"], "name" => $row["name"], "price" => $row["price"], "image" => $row["image"] ); } $data .= "</li>"; return $data; } else { return "<h1>Oops... Something went wrong!</h1>"; } } } } } *** INIT.PHP *** <?php // db connection $host = "localhost"; $user = "root"; $pass = "root"; $db = "cart"; $Conn = new mysqli($host, $user, $pass, $db); // error reporting ini_set("display_errors", 1); mysqli_report(MYSQLI_REPORT_ERROR); // constants define("shop_name", "Tremendous Toys"); define("main_path", "localhost/web_apps/shopping_cart/"); define("image_path", "localhost/web_apps/shopping_cart/images/"); // includes include("models/m_shopping_cart.php"); include("models/m_products.php"); // object integrations $Shopping_Cart = new Shopping_Cart(); $Products = new Products(); // session initialisation session_start(); *** INDEX.PHP *** <?php include("init.php") ?> <link rel="stylesheet" href="visual/style.css" type="text/css"> <body> <div id="whitespace"> <h1><?php echo shop_name ?></h1> <?php $Products->fetch_all_products(); ?> </div> </body>
-
- shopping cart
- database
-
(and 3 more)
Tagged with:
-
A question about MySQL beginners course, part of connecting mysql with php, the video was very quickly and i didnt understand well. 1) Is there any simple way to connect a user to a database without such apps such cPanel? (from MyAdmin) 2)You told - "I am just using cPanel to connect a user with a database". Is there some free cPanel alternative that would work good on both mac and windows operating systems? For example i found some alternatives but on the download page i didnt see macos supported.
-
Php Buddies, I'm going to jump into building my own searchengine now. Starting off with the search box, then the index and then finally the crawler. Not too worried about the crawler. Gonna make use of cURL and implode,explode, etc. php functions. It's the Index that I quite can't get my head around. To build the Index, should I have the structure of the mysql tbl like this .... ? Option 1 Columns Url|Keywords Or, should I make the structure like this instead ..... ? Option 2 Columns Keyword|Urls Option 1a Example Columns Url | Keywords ----------------------------------------------------------------------- devshed.com | forum, programming, php Option 1b Example Columns Keyword | Urls -------------------------------------------------------------------------------------------------------------------------- forum | devshed.com, blackhat.com, warriorforum.com --------------------------------------------------------------------------------------------------------------------------- php | devshed.com/forum/php.htm, sitepoint.com/forum/php.php Option 2a Example Columns Urls | Keyword ----------------------------------------------------------------------- devshed.com | forum ----------------------------------------------------------------------- devshed.com | programming ----------------------------------------------------------------------- warriorforum.com | money ----------------------------------------------------------------------- warriorforum.com | forum Option 2b Example Columns Keywords | Urls -------------------------------------------------------------------------------------------------------------------------- forum | devshed.com/forum -------------------------------------------------------------------------------------------------------------------------- forum | blackhat.com/forum --------------------------------------------------------------------------------------------------------------------------- php | devshed.com/forum/php.htm --------------------------------------------------------------------------------------------------------------------------- php | sitepoint.com/forum/php.php Question 1: I have a feeling you won't like Option 1a or 1b atall. But, let's assume you need to do it out of them 2 options. Which one would you choose ? Question 2: I have a feeling you will like Option 2a or 2b. Which one would you choose ? Or, if you don't like any of them 2. Then, let's assume you need to do it out of them 2 options. Which one would you choose ? Question 3: If you don't like the structure of any of the 4 options then which structure would you yourself use or have used ? Best to show an example like I did. Btw, I know that, if I structure my tbl around the way I showed in my examples then users would only be able to make queires for a single keyword and not a phrase. But, dealing with phrases get complicated and so for the time being, as a beginner, let's concentrate one thing at a time. Concentrate on the very first basic of indexing a url. Thanks
-
Hi, I am developing a php-mysql website hosted in an apache. The site is down since yesterday for my IP address, whereas it is visible elsewhere. The web hosting company said they do not see any problems and my IP is not blocked by them. The problem has occured before and was solved by itself after a few days. I simply do not understand the reason behind it. Annoying as I have to stop working on the site till it is restored. Please help. Cheers.
-
I have received so much help from this site and the amazing people on it. I am humbled by the amount of knowledge everyone here has. I am hoping that you can help me with something that I am struggling to figure out. I have a check box that successfully writes to my db but I can only get it to work with 1 and 0. I would like checked = yes unchecked to = no but I cant figure it out. Here is the code I am currently using. <strong>Active: *</strong> <input type="checkbox" name="Active" value="1" <?php if($Active == 1) echo 'checked="checked"'; ?>"/><br/> and $Active = (int)$_POST['Active'];
-
Is it possible to have 2 or 3 tables in a database example Table 1 = names Table 2 = address Table 3 = phone numbers and when I fill in my name and number on a form it writes the name to the name table and number to the number table and then I can build a query to pull the phone that goes with the right name? Is it better to spilt it up this way for security or it doesn't really matter? I just feel like I have way to many rows in a single table on my database.
-
I am using the code from Basic PHP System: View, Edit, Add, Delete records with MySQLi and I am wanting to add some code that will display a total number of results returned from a query. if ($result = $mysqli->query("SELECT * FROM clients where (`clients`.`aftercare` = 'yes')ORDER BY LastName ASC")) My question is how can I display how many records are returned. So for example I run it and it returned 40 names. I would like to add something to the page that says 40 people found. I am sure this is probably very simple, but I am brand new to all of this. Thank you for you help in advance.