Jump to content

nebrer

New Members
  • Posts

    6
  • Joined

  • Last visited

nebrer's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. I got it now. Thank you so much. I changed it to: $mysqli = new mysqli("myhost","myusernamne","mypassword",'bikes'); Now I can carry on building Have a great weekend. Rickard
  2. Can´t you use include ('mysqlcondb.php'); I tryed this and of course it did´t work. <html> <head> <TITLE>database</TITLE> <link href="style1.css" rel="stylesheet" type="text/css" media="screen" /> </head> <body><center> <div id="latest-post-wrap"> <div id="latest-post" class="post"> <p class="byline"></p> <h1 class="title"><a href="#">database</a></h1> <div class="entry"> </center> <?php $mysqli = new mysqli(myhost,myusernamne,mypassword,'bikes'); // Make a MySQL Connection $sql = "SELECT m.modell , m.antal , o.total , ROUND(o.total/m.antal*100, 1) as pc FROM modeller m LEFT JOIN ( SELECT mc as modell , COUNT(*) as total FROM owner GROUP BY modell ) o USING (modell) ORDER BY modell"; $res = $mysqli->query($sql); // execute the query while (list($model, $antal, $total, $pc) = $res->fetch_row()) { // list the results echo "We have $total pcs $model ( {$pc}% ) of produced $antal pcs in the database<br>"; } ?> <?php ## close connection! mysql_close($connect);?> test </html>
  3. Ohh. Many years since I did any programming and I did´t know about mysqli.
  4. Thanks again. I will try tomorrow. Have a nice weekend Rickard
  5. Thanks Barand. As I wrote before " I´m a beginner" and don´t realy get where I should insert the code. I need a little more guidance. Sorry. Rickard
  6. I have a owners registry database for motorcycles ( vintage ) Database name: bikes Tables : owner & modeller Columns in owner: mc Columns in modeller: modell and antal Today the owner can type in their model and that ends up in table "owner" column "mc" I have a table ( modeller ) with produced number of each model In column "modell" are the different models In column "antal" are the produced number of each model Today I can present how many of each model there are in the database. I wish to calculate how many of each model we have in the database compared to produced. Ie: We have 100 pcs B50 ( 20% ) of produced 500 pcs in the database We have 100 pcs B25 ( 10% ) of produced 1000 pcs in the database Todays code that shows how many of every different models we have Rickard Beginner from Sweden Sorry English is not my first language. <?php ## databas koppling! include ('mysqlcondb.php'); // Make a MySQL Connection { $query = mysql_query("SELECT * FROM owner "); if (!$query) die(mysql_error()); $numrows = mysql_num_rows($query); echo "<br />Here are <b>"; echo $numrows; echo "</b> Bikes in owners database <br><br>"; } $query = "SELECT *, COUNT(mc) FROM owner GROUP BY mc"; $result = mysql_query($query) or die(mysql_error()); // Print out result while($row = mysql_fetch_array($result)){ echo "There are ". $row['COUNT(mc)'] ." ". $row['mc'] .""; echo "<br />"; } ?> <?php ## close connection! mysql_close($connect);?>
×
×
  • 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.