Jump to content

thowe26

New Members
  • Posts

    8
  • Joined

  • Last visited

Everything posted by thowe26

  1. Thanks Muddy Appreciate your time. All works exactly as you say.
  2. Hi Muddy Thanks for your help and your comments, much appreciated. But no luck. I added a blank href to allow me to click, swapped the { and ( around after the $.ajax. and simplified the returning 'hello.php' so it is just an echo 'hello' (the original 'printers3.php' is a multi row array) But no luck. Here is the file in its full, so very simple. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title></title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <meta name="robots" content="noindex"> <link href="css/3D1.css" rel="stylesheet" type="text/css" /> <script type="text/javascript" src="jquery-1.3.2.min.js"></script> <script> function myMenuFunction(dest){ $.ajax{( url: dest, type: "GET", success: function ajaxSuccess(data){ $('#MiddleColumnWrapper').empty(); $('#MiddleColumnWrapper').html(data); }, fail: function ajaxFailed(e){ alert("Server call failed with the following message : "+e); } ); }; }; </script> </head> <body> <ul > <li><a href="" onClick="myMenuFunction('hello.php')" name="3D Printers" title="3D Printers">3D Printers3</a></li> </ul> <div id="MiddleColumnWrapper"> <p>Middle column</p> </div> </body> </html>
  3. Have done - no luck Couple of questions about your code. Apologies if they are basic but I have been trying every combination Should: "$.ajax({" be "$.ajaxLink({" so it picks up the class in the anchor. Although I have tried this and no luck Taking the href out then does not provide the link thru to the printer3.php interrogation file. Although I have tried this and no luck.
  4. Hi Muddy This is the essence of what I have, The menu option is in an include and printers3.php interrogates the database and finishes with a "echo $table". That all works ok, I just cannot seem to get the result to sit inside my #MiddleColumnWrapper. The echo still presents in a new window. <head> <script type="text/javascript" src="jquery-1.3.2.min.js"></script> <script> $( function() { $.ajax({ url: ajaxUrl, type: "get", success:function loadDiv( response ) { $( "#MiddleColumnWrapper" ) .html( response ); } } } </script> </head> <body> <ul > <li><a href="printers3.php" Class="ajaxLink" name="3D Printers" title="3D Printers">3D Printers3</a></li> </ul> <div id="MiddleColumnWrapper"> <p>Middle column</p> </div> </body> </html>
  5. Hello Complete newbie but learning! I have a php file presenting my menu eg <li><a href="printers3.php" class="ajaxLink" name="Printer area" title="Printers3">Printers3</a></li> and I am trying to include the output from printers3.php (the final line is echo $table; ) later on in the code within <div id="MiddleColumnWrapper"> I have put the following code in my </Head> <script> $( function() { $( ".ajaxLink" ).on( "click", function() { var ajaxUrl = $( this ).attr( "href" ); $.get({ ajaxUrl, function( response ) { $( "#MiddleColumnWrapper" ) .html( response ); } }); } } </script> But at the moment I just get the result of $table in a new page. Have I missed something Thanks
  6. Hello again The attached file PrinterMysql is my original attempt, wrong and messy but it does retrieve data, so i know that bit is right? PrintersMysql.php Using the same connection definitions in PrinterPDO I pull a blank, no data. the errorinfo shows: ..Array ( [0] => [1] => [2] => ) 1.. PrintersPDO.php Help
  7. Hello again Thanks for your quick response. I have tried to use this code but the page comes back with a ...Invalid argument supplied for foreach()... I think i have had this error when nothing is retrieved from the database? The definitions I have plugged into your code are exactly the ones I used (and got some kind of response) with my previous code. just fyi my Database is called machines as is the Table I am trying to query (sorry!) is it something I have not copied correctly in the $pdo statement? although I have gone thru it with a fine toothpick. To keep it simple I have put your connection code and the table code into one simple file.: do you have a snippet of error checking code I could plug in to check the connection etc. Thanks for your help - appreciated. I set myself the task of learning php/mysql and it looks like I now need to learn pdo. <?php //definitions for the connection: define('DSN','mysql:host=localhost;dbname=machines'); //pdo dsn define('USER','root'); //pdo user define('PW','xxx'); //pdo password //connect to the database: $pdo = new PDO(DSN,USER,PW,array(PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC)); //setting the default fetch mode to associative array. $table = '<table cellspacing="3" cellpadding="3">'; //start our table, I usually hold the building in a variable, for output later. $query = "SELECT MachineName ,BedSizeX, FROM machines"; //This is the query we send to mysql. $i = 0; //This is a control variable. foreach($pdo->query($query) as $row) { //since we use a standard query, you can call it in a foreach to get each row. if($i == 0) { $keys = array_keys($row); //we get the column names. $table .= '<tr><th>' . implode('</th><th>',$keys) . '</th></tr>'; //and add them as table headers. ++$i; //then increment our control so that this block will not run again. } $table .= '<tr><td>' . implode('</td><td>',$row) . '</td></tr>'; //then we populate the fields of the table with our data. } $table .= '</table>'; //Then we end the table. echo $table; ?>
  8. Hello I am a complete newbie. I have tried a few snippets without success. I am trying to present the results from an sql query into a web page. The query has multiple columns and multiple rows I can print my headers with: // printing table headers for($i=0; $i<$fields_num; $i++) { $field = mysqli_fetch_field($result); echo "<td>{$field->name}</td>"; } echo "</tr>\n"; But having problems working out how to print my data This is what I have from this forum but its only for one column and I cannot work out how to make work for multiple columns <table cellspacing="3" cellpadding="3"> <?php $query = "SELECT MachineName ,BedSizeX, Weight FROM machines"; $result = mysql_query($link, $query) or die("There was a problem with the SQL query: " . mysql_error()); if($result && mysql_num_rows($result) > 0) { $i = 0; $max_columns = 3; for($row = mysql_fetch_array($result)) { // make the variables easy to deal with extract($row); // open row if counter is zero if($i == 0) echo "<tr>"; // make sure we have a valid product if($product != "" && $product != null) echo "<td>$product</td>"; // increment counter - if counter = max columns, reset counter and close row if(++$i == $max_columns) { echo "</tr>"; $i=0; } // end if } // end for } // end if results // clean up table - makes your code valid! if($i > 0) { for($j=$i; $j<$max_columns;$j++) echo "<td> </td>"; echo '</tr>'; } ?> </table> Thanks in advance
×
×
  • 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.