Jump to content

mr cracker

Members
  • Posts

    14
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

mr cracker's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Thanks for your reply. You are right, i didn't have an active connection, i tried your way and it works great and more effectively , i will use it from now on, but it's still not clear for me why do i have to return $con. (I know i must do it because i don't have an active connection but i don't get why, i don't know what $con is equal to or why is it important) So the way i'm seeing this is that without returning $con like this: class Connect { public static function con() { $con=mysql_connect("localhost","root","");// Connects to DB??? mysql_query("SET NAMES 'utf8'"); // Sets charset to UTF8 mysql_select_db("blog"); // Selects the DB } } And when running this: mysql_query($somequery,Connect::con());// Entire method con() is run? or is it just passing the returned value if any? whatever that is Wouldn't php run all 3 lines inside the method/function con() and start a new connection when the the first line is run? with no need to return anything. Thanks for your time.
  2. Hello all. I'm learning Object oriented php and found this simple piece of code online but i don't understand why the variable $con must be returned: class Connect { public static function con() { $con=mysql_connect("localhost","root","");// Connects to DB??? mysql_query("SET NAMES 'utf8'"); // Sets charset to UTF8 mysql_select_db("blog"); // Selects the DB return $con; // Don't know why $con must be returned, but it wont work without this. } } $con is later used in the script like this from another class to run a Query: mysql_query($somequery,Connect::con()); Thanks for your help.
  3. Thankyou both, i had been there stuck for hours now Thank you.
  4. Thanks for your reply. Using the above code i get this error: Parse error: syntax error, unexpected T_VARIABLE in C:\xampp\htdocs\.... on line 370 $tax1 = $row['concepto']; <------ This is Line 370
  5. Hello, i need help with this please. I have this table in my DB I want to store the concepto column´s values in 2 php variables so i'll end up with this: $tax1=IEPS; $tax2=IVA; i'm using this query but its not working: $result = mysql_query("SELECT concepto FROM tbl_nimpuestos WHERE numventa = '$z' "); $row = mysql_fetch_array($result) $tax1 = $row[0]; $tax2 = $row[1]; $z is equal to 28 so i know that's not the problem. THANKS!
  6. ok, now i get it. Thank you
  7. Thank you, its working nicely now. I'm a begginer. Why do i have to "escape" them ?
  8. Hello. i have this code: $tabla="tbl_familias"; //NOMBRE DE LA TABLA A MOSTRAR $result = mysql_query("select * from $tabla"); echo "<table bgcolor=\"#DBEDE9\" align=center style=\"border:5px outset green\">"; for ($i = 0; $i < mysql_num_fields($result); $i++) { print "<th>".mysql_field_name($result, $i)."</th>\n"; } while ($registro = mysql_fetch_row($result)) { echo "<tr>"; foreach($registro as $clave) { echo "<td bgcolor=\"white\"style=\"border:2px groove black\" align=\"center\">",$clave,"</td>"; } } echo "</tr></table>"; i get this table: but its too small, and i want to make it bigger / wider. I've tried using width like this: echo "<table bgcolor=\"#DBEDE9\" align=center width="600" style=\"border:5px outset green\">"; but i get: Parse error: syntax error, unexpected T_LNUMBER, expecting ',' or ';' Thanks.
  9. THank you! i hadn´t noticed the extra bracket. sorry. its working now
  10. Hello. I´m having a problem with this Query: $fecha=$_POST['fecha']; $result = mysql_query("SELECT * FROM tbl_ventas WHERE fecha = (str_to_date('$fecha', '%d/%m/%Y')"); but it returns an error in MYSQL Syntax. The variable $fecha contains the date the user selects from a calendar in this format in example: 1-5-2010 (d/m/y). i want to convert that date format into MySQL´s YYYY-mm-dd so i can then select only the matching records in the table tbl_ventas. THANKS!
  11. Thank you both, now its working correctly!!!
  12. Thanks for your reply. I changed the code to look like this: $query = "SELECT concepto, COUNT(concepto) As conceptocount As FROM tbl_ventas GROUP BY concepto ORDER BY conceptocount"; $result = mysql_query($query) or die(mysql_error()); // Print out result while($row = mysql_fetch_array($result)){ echo "There are ". $row['conceptocount'] ." ". $row['concepto'] ." items."; echo "<br />"; } but i get this error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'As FROM tbl_ventas GROUP BY concepto ORDER BY conceptocount'
  13. Hello Guys! I have the following table: Using this code: $query = "SELECT concepto, COUNT(concepto) FROM tbl_ventas GROUP BY concepto "; $result = mysql_query($query) or die(mysql_error()); // Print out result while($row = mysql_fetch_array($result)){ echo "There are ". $row['COUNT(concepto)'] ." ". $row['concepto'] ." items."; echo "<br />"; } I get this result: There are 3 Coca Cola 600ml items. There are 5 Leche items. There are 2 Sprite 600ml items. But they are ordered alphabeticaly and i want them to be ordered numericaly in a DESCENDIG order like this: There are 5 Leche items. There are 3 Coca Cola 600ml items. There are 2 Sprite 600ml items. i know i have to use ORDER BY , and i´ve tried it but with no luck. Thanks.
  14. Hello Guys, First Post!!! I´ll try to explain myself the best i can. So, im writting a 7 eleven kind of program to use the computer as a cash register. Let´s say i am at the cash register/computer so a customer buys 2 or 3 cokes. So i have this form and textarea in my program in which you insert the barcode numbers of the product, so you hit enter and it connects to de DB and checks for the corresponding barcode and returns the product, price etc. and it should display it in the screen in the space between the Registered Products line and the send button (see image below). and then you insert the next product´s barcode and it should display below the first one and so on until you register all of them. The form action is set to registroproducto.php and this is the php code of that file <?php// RETRIEVES THE BARCODE $codigobarras=$_POST['codigobarras']; // DB CONNECTION mysql_connect("localhost", "root", "") or die(mysql_error()); mysql_select_db("bd_sistemaventas") or die(mysql_error()); // CHECKS FOR A BARCODE MATCH IN DB AND DISPLAYS THE PRODUCT INFO $result = mysql_query("SELECT codigobarras,familia,descripcion,precio,costo,proveedor FROM tbl_productos WHERE codigobarras = '$codigobarras'"); if (!$result) { echo 'No se puede ejecutar el query: ' . mysql_error(); exit; } $row = mysql_fetch_row($result); echo $row[0]; // codigo de barras $descripcion = $row[2]; // descripcion $precio = $row[3]; // precio // INSERTS THE JUST REGISTERED PRODUCT IN THE DB SO I CAN SAVE IT SOMEWHERE AND DISPLAY IT WITH THE NEXT REGISTERED PRODUCTS IN A LIST LIKE FORM mysql_query("INSERT INTO tbl_ventas (id_venta, numventa, concepto, precio) VALUES('', '1', '$descripcion', '$precio') ") or die(mysql_error()); ?> I have no idea how to do it, i´ve tried for 4 hours straight and did not work. please help. Thank you Guys!
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.