Jump to content

Levan

Members
  • Posts

    12
  • Joined

  • Last visited

    Never

Everything posted by Levan

  1. mysql_result error code mysql_results($resultset,0) if the resultset is empty should return an error.....however the ERROR_NO is 0 and no message is provided.... is that a bug is PHP or mysql or neither?
  2. Ok then just so I can clarify this in my own head . In the example above $time is the unique key for the database that in some cases a user may attempt to create a duplicate....I am adding 1 to $time and rerunning the INSERTION in my error function. However the variable $time is not passed to the function and therefore is not available within the function. To enable me to do what I intend I will need to all the variables into the function ....maybe a function is not exactly what I need here..... Will redesign I think
  3. Quick query: I have database connect script at the beginning of my PHP page which sets the dbconnection. when I run a query in the script it works fine I have decided that rather than use the default error catch like this: $result=mysql_query($query,$db_connect) or die("There has been an error adding the appointment to the database.".mysql_error()); which works fine I would call a function to handle the errors - particularly in the case of a duplication like so: function mysql_error_check(){ $error_num=mysql_errno(); $error=mysql_error(); echo $error_num.':'.$error; switch ($error_num){ case '0': break; case '1062': $time=$time+1; mysql_select_db($database_db_connect, $db_connect); $query="INSERT INTO `appointment` (`Time`, `Details`, `PatientID`, `Type`, `Vet_init`,`Room`) VALUES ('$time', '$detail', '$petid', '$type', '$vet','$room')"; $result=mysql_query($query,$db_connect) or die("There has been an error adding the appointment to the database. <a href=\"http://".$config_host.$config_dirhost."/".$extra."\">Click here to return to the main appointment page.</a> Error:".$error); break; default: echo "Default Switch"; die("There has been an error adding the appointment to the database. <a href=\"http://".$config_host.$config_dirhost."/".$extra."\">Click here to return to the main appointment page.</a> Error:".$error); break; } The problem is when the function is called it doesnt seem to be able to use the link identifier to access the mysql database the following error is generated Warning: mysql_select_db(): supplied argument is not a valid MySQL-Link resource in myfile.php on line 31 Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in myfile.php on line 33 Given the db_connect script is the first thing I call as a required script and it does work if the error function doesnt get called (ie no error occurse ) and that the dbconnect parameters are defined before the funtion is called. Why do I get this error.....
  4. Okay this is basically a server overhead question. I have a client database which I access using php. On one particular page I have php creating javascript which dynamically allows a formfield to be autofilled.  The autofill options are created based clients...eg.  If you name was Smith, Joe.  As the person inputing type S it would show all S clients, then Sm just clients last names beggining with Sm...etc... At the moment my test database has 3 clients...(keeps it simple) However anyone hazard a guess at the effect on server overhead/processing, and client side processing on the javascript if the database say had around 10000 clients....is this unreasonable....??
  5. Yep the table works fine if you remove the are outputting the mysql data Appseconds is defined as 900.
  6. I have a do-while loop that outputs a table with a series of times down one column.... The concept is a day-planner. In the details section each time a row is produced it checks that the mysql query I have defined doesnt have a record with that particular time.  However the  system seems to go into an infinite loop and I cannot see why...code to follow... First code excerpt...the mysql query... [code]<?php mysql_select_db($database_db_connect, $db_connect); $query_appointments = sprintf("SELECT * FROM appointment WHERE `Time` >= '%s' AND `Time` <='%s' ORDER BY `Time` ASC",$begindayunix,$enddayunix); $appointments = mysql_query($query_appointments, $db_connect) or die(mysql_error()); $row_appointments = mysql_fetch_assoc($appointments); $totalRows_appointments = mysql_num_rows($appointments); ?>[/code] The next excerpt is the table creation loop and inbuilt mysql check... [code] </table> <table width="100%" border="1" cellpadding="0" cellspacing="0" bordercolor="#CCCCCC"> <?php  do{ //simply gets the unix time for the current appointment slot and converts it. $currentapp_array=getdate($currentapptime); if ($currentapp_array['hours']<10){$hours="0".$currentapp_array['hours'];}else{$hours=$currentapp_array['hours'];} if ($currentapp_array['minutes']<10){$minutes="0".$currentapp_array['minutes'];}else{$minutes=$currentapp_array['minutes'];} ?>   <tr bordercolor="#999999" nowrap="nowrap"   <?php //checks if its lunch time and greys out those slots.     if ($currentapptime  > $lunchbeginunixtime AND $currentapptime < $lunchendunixtime){echo 'bgcolor="#DDDDDD"';}else{echo 'bgcolor="#FFFFFF"';} ?>   >   <td width="10%" align="center"><a href="createappointment.php?Time=<?php echo $currentapptime;?>"><?php echo $hours.":".$minutes;?></a></td> <?php if ($currentapptime=$row_appointments['Time']){?> <td width="70%"><?php echo $row_appointments['Details'];?></td> <td width="20%"><?php echo $row_appointments['PatientID'];?></td><?php }else{ ?> <td width="70%"></td> <td width="20%"></td> <?php } ?> <?php $currentapptime=($currentapptime+$appseconds);}while($currentapptime<$endtime);?> </table> [/code] I assumed that once I have processed a row from my query it moves to the next row....I think I am probably wrong in that regard...I am going to reverse the loops and see if that works any tips would be great... Lev
  7. DON'T WORRY !!! I sorted it out the answer of course was to use a INNER JOIN SELECT * FROM brand INNER JOIN brandcat ON brand.brandkey = brandcat.BrandID WHERE brandcat.CatID = ? Brilliant I am slowly getting the hang of this MySQL/PHP stuff Lev
  8. Hi there I am having trouble with a sql query I may be going about this entirely the wrong way. I am trying to set up a product database where each product is classified by its Brand and each brand by a category. However some brands may fall into 2 categories. SO I created a 4th table which consisted of a primarykey a BrandID column and a categoryID column. SO I have 4 tables - products, brands, categories, and brandcat the link between categories and brands. Now I have created the following query which takes a http get variable which is the category id and I want to return the brand names and brand descriptions that fall in that category. here is what I came up with... [code] $colname_BrandID = "-1"; if (isset($_GET['id_brand'])) {   $colname_BrandID = (get_magic_quotes_gpc()) ? $_GET['id_brand'] : addslashes($_GET['id_brand']); } //This first query gets the brandID that fall into the category selected mysql_select_db($database_dbconnect, $dbconnect); $query_BrandID = sprintf("SELECT BrandID FROM brandcat WHERE CatID = '%s'", $colname_BrandID); $BrandID = mysql_query($query_BrandID, $dbconnect) or die(mysql_error()); $row_BrandID = mysql_fetch_assoc($BrandID); $totalRows_BrandID = mysql_num_rows($BrandID); //This Query then uses the returned id's to bring the results from the brands table mysql_select_db($database_dbconnect, $dbconnect); $query_brands = sprintf("SELECT * FROM brand WHERE brandkey = '%s'", $row_BrandID); $brands = mysql_query($query_brands, $dbconnect) or die(mysql_error()); $row_brands = mysql_fetch_assoc($brands); $totalRows_brands = mysql_num_rows($brands); [/code] Essentially as you can see the second query actually nests the first. When I run it with a value of 1 in the id_brand I get no results..mind you I get no php errors either I am running using a repeating do-while function as below [code]     <?php $i=1;           $bg_color="#FFFFFF";?>     <?php do { ?>     <?php     $bg_color="#FFFFFF";     if ($i % 2 == 0){$bg_color="#FFFF99";}          $brandname=$row_brands['brandname'];         $brandid=$row_brands['brandkey'];?>           <tr bgcolor=<?php echo $bg_color; ?>><td><div align="left">       <h3><a href="items.php?id_item=<?php echo $brandid; ?>&amp;id_itemcat=<?php echo $row_catcheck['catkey']; ?>"><?php echo $i; ?> . <?php echo $brandname; ?></a></a></h3>       <blockquote>         <p><?php echo $row_brands['branddesc']; ?>             </p>           </blockquote>       </div>   </td>       <td width="10%"><div id="image"><a href="#nogo" class="p1"><img src="images/products/brand<?php echo $brandid; ?>.gif" alt="Hover for full image" width="95px" height="95px"/><img class="large" src="images/products/brand<?php echo $brandid; ?>.gif" alt="Hover for full image"/></div></td>   </tr><?php $i++;?> <?php       }       while ($row_brands = mysql_fetch_assoc($brands)); ?> [/code] brandname, brandkey, branddesc are the column names from the sqldatabase I think that what I need to do is make the first query into a function that I can call from within nested do while loop is that correct - well until someone points me in another direction thats what i will do. Lev
  9. Dont I feel light a right wally... Thanks mate - such a simple fix
  10. Does the data created about the machines status need to recorded for posterity or can you dump it afterwards... If the data needs to be stored ..use a database...and time stamp each entry as it goes in. You can create 1 webpage using php designed form to enter the data directly into the database. You can then use another table to output the data and view it. You can order the data by date or by who entered it...just about by anyway as long as you stored the info first... So you dont need any application ...you will need a webserver(apache is good) installed on the network that can process php pages. And a installation of mySQL if thats the database that you choose to use. Both are public GNU but read the licence to make sure your use falls into the right category. I use a package called WAMP on my windows based machine to test all my code before I upload to the www. Google wamp for windows. or LAMP if u use linux. I think there is a package for mac as well but I dont know the name.. Lev
  11. I am only new to this PHP stuff and feel free to explain why this way is not as effective as the method using a database could you create a php file called for eg link.php in which you define variables which define the links... ie $home_page=".\somewhere\home.php $link_page=".\somewhere\link.php and then include this file and call the variables when you need them.... then you just update your include file as required Lev Ooops you wouldnt call the file links.php and then define it in the variables you would call it include_links.php or something then in the top(before the header) of each page you wanted to call the links you would do [code] <?php require_once('./include_links.php'); ?> [/code] you can then call the defined variables anytime you need them Lev
  12. Hi all, I am attempting to build a PHP page (based on 4.03) linking to a MYSQL data base. I have coded a table to output the data in two ways. Basically using a while loop to repeat the table rows I have include a variable $i that increments and using the % (modular??) to check for a remainder I change the back ground of each cell to ease readibility in a long result. In the first example I basically built the code entirely in php echoing all the html Here it is [code] <table width="90%" height="100%" border="1" bordercolor="#003300" bgcolor="#FFFFFF">     <?php $i=1;?>   <?php   /* Create a repeatable row of cells to hold both the categories and descriotions and an image using the catkey.  Images should be stored in ./images/ with the name category(cat number).gif.     */           do {     $bgcolor="#FFFFFF";     if($i%2 == 0){$bgcolor="#FFFF99";};     echo "<tr bgcolor=$bgcolor><td bgcolor=$bgcolor><blockquote><h3 align=\"left\">";     echo "<a href=\"./brands.php?id_brand=",$row_categories['catkey'],"\">";     echo "$i.";     echo $row_categories['catname'];     echo "</a></h3><blockquote><p align=\"left\">";     echo $row_categories['catdesc'];     $i++;     echo "</p></blockquote></blockquote></td>     <td width=10%><img src=\"images/category";     echo $row_categories['catkey'];     echo ".gif\" width=\"100\" height=\"100\" align=\"absmiddle\"/></td></tr>     ";     }     while ($row_categories = mysql_fetch_assoc($categories)); ?>   </table> [/code] This works as expected no problems However in the next example the background doesnt change... [code] <table width="90%" border="1" bordercolor="#003300" bgcolor="#FFFFFF" id="brand">       <?php $i=1;           $bg_color="#FFFFFF";?>     <?php do { ?>     <?php if ($i % 2 == 0){$bg_color="#FFFF99";}          $brandname=$row_brands['brandname'];         $brandid=$row_brands['brandkey'];?>                  <tr bgcolor=<?php echo $bg_color; ?>><td><div align="left">         <h3>         <a href="items.php?id_item=<?php echo $brandid; ?>&id_itemcat=<?php echo row_catcheck['catkey']; ?>"><?php echo $i; ?> . <?php echo $brandname; ?></a></a></h3>       <blockquote>         <p><?php echo $row_brands['branddesc']; ?>             </p>           </blockquote>       </div>   </td>       <td width="10%"><div id="image"><a href="#nogo" class="p1"><img src="images/products/brand<?php echo $brandid; ?>.gif" alt="Hover for full image" width="95px" height="95px"/><img class="large" src="images/products/brand<?php echo $brandid; ?>.gif" alt="Hover for full image"/></div></td>   </tr><?php $i++;?> <?php       }       while ($row_brands = mysql_fetch_assoc($brands)); ?>   </table> [/code] So I used the same piece of code to change the background but in the second example it doesnt work ...the background changes to the second color and remains that way... An explanation would be appreciated... I can link in the website if anyone needs explanation but I didnt think it was required.
×
×
  • 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.