
Juarez
Members-
Posts
16 -
Joined
-
Last visited
Profile Information
-
Gender
Not Telling
Juarez's Achievements

Newbie (1/5)
0
Reputation
-
Hi I have a shopping cart whereby the product details for each product are loaded from the MYSQL database into an array and echoed out onto the product page. I have been trying to change it so that the product has size options selected from a drop down and the selection then onchange will update the price accordingly. I assume the best way to do this is to have the two product options a small and a large with different prices stored in the database with different ID's. Then when the dropdown is changed to small for example the id for small is posted to the function which retrieves the product details. I think its a matter of adapting the function below to a condition where if the value posted is 's' then id = 1 else if value posted is 'L' then id = 2. in a variable, Though someone may have a better way of doing this. I have so far been unable to make this work. Any help would be appreciated. Here is the code to select the products from the database into an array. /** * finds products and lists them in DESC order * @return array */ function find_products() { db_connect(); $query = "SELECT * FROM products WHERE products.id = '1' "; $result = mysql_query($query); $result = db_result_to_array($result); return $result; } here is code which could post the drop down selection to the function above form name="SelectSize" action="DatabaSelectPage.php" method="post" ;> <p style = "font-family: Arial, Helvetica, sans-serif; font-size: 14px "> <select name="UpdatePrice" id="UpdatePrice" onchange="this.form.submit();" method="post"> <option value=""></option> <option value="S">S</option> <option value="L">L</option> </select> here is the code which echos out the product details from the array <?php foreach($products as $product): ?> <li> <a href="#"> <img src="../images/shop/<?php echo $product['myimage']; ?>" /> <h3><?php echo $product['title']; ?> -<br> £<?php echo number_format($product['price'], 2); ?></h3> <h3><?php echo $product['body']; ?></h3> <!--<h4><p><a href="index?view=add_to_cart&id=<?php echo $product['id']; ?>">add to cart</a></p></h4>--> </a> </li> <?php endforeach; ?>
-
Great! thanks for the tip.
-
Hi. So I'm trying to echo out all the columns from the table. I'm connecting to SQL Server by the way. The number of columns in the table will vary so I want to loop and echo all the columns in the table without specifying. Its working but its echoing each column twice into the table. Any idea why this is? Thanks echo "<table border='1'> <tr> <th>start</th>,<th>end</th>" . join('</th><th>', $cols) . "</th> </tr>"; $tsql = "SELECT * FROM MYtable ORDER BY start"; /* Execute the query. */ $result = sqlsrv_query( $conn, $tsql); if ( $result ) { echo "Statement executed.<br>\n"; } else { echo "Error in statement execution.\n"; die( print_r( sqlsrv_errors(), true)); } while( $row = sqlsrv_fetch_array( $result)) { echo "<tr>"; foreach ($row as $field){ echo "<td>".stripslashes($field)."</td>"; } echo "</tr>"; } echo "</table>";
-
Thats great works well with fetch_row. and thanks for the security tips thanks Barand
-
thanks for your help so far it works very well. Only I am having a problem displaying my selected columns listed in the array @cols in my output column. I am trying to use a for each loop within the while mysql_fetch_array loop to echo each column and header , but without success. This is what I have so far.. // load column names from text file into array $cols = file('upload/PatList.txt'); array_shift($cols); // remove header $cols = array_map('trim', $cols); $selection = join(',', $cols); // create query $qry=mysql_query("SELECT ID, $selection FROM mytable", $con); // display table echo "<table border='3' width = '50'>"; // show headers echo "<tr> <th>ID</th> <th>$cols</th> </tr>"; //display query results in table while($row=mysql_fetch_array($qry)) { echo "<tr>"; echo "<td>".$row{'ID'}. "<br></td>"; foreach($row as $cols) { echo "<td>".$cols."<br></td>"; } echo "</tr>"; } echo "</table>";
-
header with a single value list. ColumnName column2 column4 column5 column8 column9
-
The table has 20 columns. id, column1, column2, column3... etc. The text file has a list with maybe 5 columns created by the user. I will echo out the ID column by default (sorry not shown in the code above) and also echo out the 5 columns named in the text file/ array ie column2, column4, column5, column8, column9.
-
Hi I have a task that a user provides a text file with a list of mysql column names from a table. I need to select and display the results from the selected columns. the column names vary each time they are provided. I have decided to load the column name list to an array and would like to use this to echo out the columns. I have made an attempt at this below but I'm not sure how to make it work. Any help would be appreciated. //load patient list to array $file = fopen("upload/PatList.txt", "r"); $all_pats = array(); while (!feof($file)) { $all_pats[] = fgets($file); } fclose($file); //var_dump($all_pats); } // select columns from array elements $qry=mysql_query("SELECT * FROM mytable", $con); while($row=mysql_fetch_array($qry)) { echo "<td>".@$row{$column_name}. "<br></td>"; }
-
passing an array as input parameters to a stored procedure?
Juarez replied to Juarez's topic in PHP Coding Help
thanks, I'll look into this method -
passing an array as input parameters to a stored procedure?
Juarez posted a topic in PHP Coding Help
Hi I will be receiving a text file with the values below on a regular basis. I'm creating a form where the final aim is to import each row of these values and use each row of values as the parameters of a stored procedure in MYSQL. There is only one stored procedure so I will run the stored procedure the required number of times with each row of values and output the results as one result set. My question is about the best method to achive this before I start. Would it be best to import the values to an array and then use the array as the input parameter for the stored procedure or import them to a temp table or something? chr start end chr22 50478251 50481750 chr22 50313501 50331250 chr22 50543751 50557250 chr22 50637751 50645250 chr22 50904001 50929000 thanks -
display column names from database in returned values table
Juarez replied to Juarez's topic in PHP Coding Help
Ok, I'll look into using PDO and consider myself properly told off... thanks -
display column names from database in returned values table
Juarez replied to Juarez's topic in PHP Coding Help
Ok, sorry I forgot mention if the user is entering only the key number from the array and this is being posted rather than the column name how you you then return the column name from the database. -
display column names from database in returned values table
Juarez posted a topic in PHP Coding Help
Hi. I have a html seach form and a php page. basically a user can enter the column name selections in the search boxes and select the relevent columns from the database. the data is returned dynamically to a table with mysql_fetch_array but I would like the column names from the database displayed at the top of returned table. thanks //index.html <html> <head> <title>Search the Database</title> </head> <body> <form action="search_column.php" method="post"> <br /> Search ID1: <input type="text" name="column1" /><br /> Search ID2: <input type="text" name="column2" /><br /> Search ID3: <input type="text" name="column3" /><br /> <br /> <br /> <input type="submit" name="submit" value="Submit" /> </form> </body> </html> //search_column.php <?php require_once('includes/connection.inc.php'); $column1 = $_POST['column1']; $column2 = $_POST['column2']; $column3 = $_POST['column3']; $qry=mysql_query("SELECT * FROM mytable", $con); echo "<table border='3' width = '150'>"; echo "<tr> </tr>"; /* Fetching the data */ while($row=mysql_fetch_array($qry)) { echo "<tr>"; echo "<td>".$row{$column1}. "<br></td>"; echo "<td>".$row{$column2}. "<br></td>"; echo "<td>".$row{$column3}. "<br></td>"; echo "</tr>"; } echo "</table>"; print( '<a href=index.html>Go back to search</a>' ); ?> -
display column names from database in returned values table
Juarez posted a topic in PHP Coding Help
Hi. I have a html seach form and a php page. basically a user can enter the column name selections in the search boxes and select the relevent columns from the database. the data is returned dynamically to a table with mysql_fetch_array but I would like the column names from the database displayed at the top of returned table. thanks //index.html <html> <head> <title>Search the Database</title> </head> <body> <form action="search_column.php" method="post"> <br /> Search ID1: <input type="text" name="column1" /><br /> Search ID2: <input type="text" name="column2" /><br /> Search ID3: <input type="text" name="column3" /><br /> <br /> <br /> <input type="submit" name="submit" value="Submit" /> </form> </body> </html> //search_column.php <?php require_once('includes/connection.inc.php'); $column1 = $_POST['column1']; $column2 = $_POST['column2']; $column3 = $_POST['column3']; $qry=mysql_query("SELECT * FROM mytable", $con); echo "<table border='3' width = '150'>"; echo "<tr> </tr>"; /* Fetching the data */ while($row=mysql_fetch_array($qry)) { echo "<tr>"; echo "<td>".$row{$column1}. "<br></td>"; echo "<td>".$row{$column2}. "<br></td>"; echo "<td>".$row{$column3}. "<br></td>"; echo "</tr>"; } echo "</table>"; print( '<a href=index.html>Go back to search</a>' ); ?> -
session variable is not retained when switching pages
Juarez replied to Juarez's topic in PHP Coding Help
Great thanks, I was wondering whether I should be using 'isset' while searching around.