Re: Question from a total newb

From: Date: Thu, 21 Nov 2002 17:41:00 +0000
Subject: Re: Question from a total newb
References: 1  Groups: php.windows 
Request: Send a blank email to php-windows+get-17069@lists.php.net to get a copy of this message
"You musn't produce sloppy code with no comments, no error checking, no indentation and no proper presentation of results until you're an expert!" Great... So as soon as I started programming in PHP, I became an expert... and now that I'm properly indenting my code and (finally) starting to use comments, I've turned into a newbie! Seriously, phpMyAdmin saved me major headaches in figuring out MySQL. -Dash Time flies like an arrow Fruit flies like a banana On Fri, 22 Nov 2002, Cam Dunstan wrote: > hey Joe, > > You ought to try some of those tools for MySQL Dash recommends, there`s some > beauties amongst them, especially phpmyadmin. In the meantime, here is a > little script, quick and dirty that will let you look at a database and > generate some basic queries and forms for you. > Just copy and paste this into a script file, change the $dbase value near > the top of the script to your database name and "run" it, it does nothing to > your database except read it and knock up some php code for you. > > Use it for two things.... > > 1. an object lesson in how NOT to program, avoid the sloppy lazy style, > total lack of comments and abysmal presentation of results. > > 2. Takes a little of the tedium out of keying up a long query or form when > you can`t remember fieldnames etc > > > But remember! youre a newbie! you mustnt produce sloppy code > with no > comments, no error checking, no indentation and no proper presentation of > results until you`re an expert! > > good luck! > > > > > <?php > > $dbase = "beadace"; > > $db = mysql_connect("localhost", "root"); > > > function friendly_date($mydate){ > // unix or mysql string type datetime to friendly dd/mm/yyyy type date > string > return date("d/m/Y", strtotime($mydate)); > } > > > > > mysql_select_db($dbase,$db); > > $underline = "-"; > for ($m = 0; $m < 60; $m++){ > $underline = $underline."-"; > } > $underline = $underline."<br>\n"; > > $result = mysql_list_tables($dbase); > $rowcount = mysql_num_rows($result); > > > for ($j = 0; $j < $rowcount; $j++){ > $tablenam = mysql_tablename($result, $j); > echo $underline; > echo $tablenam.";"; > > $fieldresult = mysql_list_fields($dbase, $tablenam); > $fieldcount = mysql_num_fields($fieldresult); > echo $fieldcount."<br>\n"; > //echo "<br>"; > > $updatestatement = "\"UPDATE ".$tablenam." SET "; > $insertprefix = "\"INSERT INTO ".$tablenam." ("; > $insertsuffix = " VALUES ("; > $formstatement = ""; > > > for ($k = 0; $k < $fieldcount; $k++){ > > $fieldnam = mysql_field_name($fieldresult, $k); > > if ((strpos($fieldnam, "hoto") > 0) || (strpos($fieldnam, "humbnail") > > 0)){ > $fieldnaminsert = $fieldnam."_name"; > } else { > $fieldnaminsert = $fieldnam; > } > > echo "&nbsp;&nbsp;&nbsp;".$fieldnam.";"; > $fieldtyp = mysql_field_type($fieldresult, $k); > echo $fieldtyp.";"; > $fieldsiz = mysql_field_len($fieldresult, $k); > echo $fieldsiz.";<br>\n"; > > $sep = "\\\""; > if (((strcmp($fieldtyp, "int") ==0)) || ((strcmp($fieldtyp, "real") > ==0))){$sep = ""; } > > $fieldlabel = ucwords(str_replace("_", " ", $fieldnam)); > > if (strcmp($fieldtyp, "datetime") == 0){ > $scriptstatement = "<"."?"."php if > ("."$"."addrec == 0){echo > friendly_date($"."myrow[\"".$fieldnam."\"])"."; > }"." ?".">"; > } else { > $scriptstatement = "<"."?"."php if > ("."$"."addrec == 0){echo > $"."myrow[\"".$fieldnam."\"]"."; }"." > ?".">"; > } > > if ($fieldsiz > 64){ > $formstatement = $formstatement.$fieldlabel."<br><textarea cols=\"40\" > rows=\"8\" > > name=\"".$fieldnam."\">".$scriptstatement."</textarea><br><br>\n"; > } else { > $formstatement = $formstatement.$fieldlabel." <input type=\"text\" > size=\"".$fieldsiz."\" name=\"".$fieldnam."\" > value=\"".$scriptstatement."\"><br>\n"; > } > > $updatestatement = > > $updatestatement.$fieldnam."=".$sep."\".$".$fieldnaminsert.".\"".$sep; > > $insertprefix = $insertprefix.$fieldnam; > $insertsuffix = > $insertsuffix.$sep."\".$".$fieldnaminsert.".\"".$sep; > > if ($k < ($fieldcount - 1)){ > $updatestatement = $updatestatement.", "; > $insertprefix = $insertprefix.", "; > $insertsuffix = $insertsuffix.", "; > } > > } > $updatestatement = $updatestatement." WHERE > > pin=\\\""."\".$"."pin.\""."\\\"\";"; > echo $updatestatement."<br>\n"; > > $insertstatement = $insertprefix.")".$insertsuffix.")\";"; > echo $insertstatement."<br>\n\n"; > > $formstatement = $formstatement."</form>\n"; > > echo "<p>View Source to inspect FORMS design code.</p>\n"; > > echo "<!--\n"; > echo "<form ENCTYPE=\"multipart/form-data\" name=\"someform\" > action=\"somescript.php\" method=\"POST\">\n"; > echo "<INPUT TYPE=\"hidden\" name=\"MAX_FILE_SIZE\" > value=\"1000000\">\n"; > echo $formstatement."<br>\n\n"; > echo "-->\n"; > > } > > ?> > > > > > > > > -- > PHP Windows Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > >

« previous php.windows (#17069) next »