nick02895 Posted September 13, 2008 Share Posted September 13, 2008 I've been trying to re-write some code I found at http://bytes.com/forum/thread519.html that creates pdf pages that I can print labels with. Issue is it wasn't written for mysql and php (now that I've been into it for several hours). I think I'm quite close, could use some help here. 2 files labels.php and print.php error I'm getting is Cannot redeclare mysql_fetch_array() on line 29 Which is the end of function 1 ----------------------------------print.php----------- <?php require_once('labels.php'); require('pdf/fpdf.php'); $cnx=db_connect(); $SelectStmt="select * from user"; PrintAddressLabels($SelectStmt); ?> ------------------------------end print.php------ --------------------------------------------------------------labels.php------- <?php //------------------connect mysql database------------------- function db_connect() { $result = mysql_connect("localhost", "username", "password"); if (!$result) return false; if (!mysql_select_db("db")) return false; return $result; } //------------------------------------function 1-------------------- function mysql_fetch_array($res) { $row = array(); $result = array(); if ($result = mysql_fetch_row($res)) { $nf = mysql_num_fields($res)+1; for($count=1; $count < $nf; $count++) { $field_name = mysql_field_name($res, $count); $field_value = mysql_result($res, $count); $row[$field_name] = $field_value; } return $row; } } //----------------------------function 2--------------- function Avery5160($x, // X co-ord of label (0-2) $y, // Y co-ord of label (0-9) &$pdf, $Data) // String w/ line breaks to print { $LeftMargin = 4.2; $TopMargin = 12.7; $LabelWidth = 66.6; $LabelHeight = 25.45; // Create Co-Ords of Upper left of the Label $AbsX = $LeftMargin + (($LabelWidth + 4.22) * $x); $AbsY = $TopMargin + ($LabelHeight * $y); // Fudge the Start 3mm inside the label to avoid alignment errors $pdf->SetXY($AbsX+3,$AbsY+3); $pdf->MultiCell($LabelWidth-8,4.5,$Data); return; } //------------------------------------------function 3--------------- function PrintAddressLabels($SelectStmt) { global $cnx; // database conneciton $pdf=new FPDF(); $pdf->Open(); $pdf->AddPage(); $pdf->SetFont('Arial','B',10); $pdf->SetMargins(0,0); $pdf->SetAutoPageBreak(false); $cur = mysql_query($SelectStmt); if (!$cur) { echo "Database Error"; return; } $x = 0; $y = 0; while ($row = mysql_fetch_array($cur) ) { $LabelText = sprintf("%s\n%s\n%s, %s, %s", $row['firstname'], $row['lastname'], $row['address'],$row['city'],$row['zip']); Avery5160($x,$y,$pdf,$LabelText); $y++; // next row if ($y == 10 ) { // end of page wrap to next column $x++; $y = 0; if ($x == 3 ) { // end of page $x = 0; $y = 0; $pdf->AddPage(); } } } else { // Error quit printing break; } } $pdf->Output(); } ?> -----------------------------------------end labels.php-------------------- Any and all comments welcome. Nick Quote Link to comment https://forums.phpfreaks.com/topic/124073-solved-cannot-redeclare-mysql_fetch_array/ Share on other sites More sharing options...
DarkWater Posted September 13, 2008 Share Posted September 13, 2008 mysql_fetch_array() is a real function already, so you can't make another one of the same name. Also, the way that you're getting the data in the function is absolutely horrid. Quote Link to comment https://forums.phpfreaks.com/topic/124073-solved-cannot-redeclare-mysql_fetch_array/#findComment-640559 Share on other sites More sharing options...
wildteen88 Posted September 13, 2008 Share Posted September 13, 2008 Remove the following function mysql_fetch_array($res) { $row = array(); $result = array(); if ($result = mysql_fetch_row($res)) { $nf = mysql_num_fields($res)+1; for($count=1; $count < $nf; $count++) { $field_name = mysql_field_name($res, $count); $field_value = mysql_result($res, $count); $row[$field_name] = $field_value; } and your code should work, all the above code does is simulate the actual built in mysql_fetch_array function. Quote Link to comment https://forums.phpfreaks.com/topic/124073-solved-cannot-redeclare-mysql_fetch_array/#findComment-640564 Share on other sites More sharing options...
nick02895 Posted September 13, 2008 Author Share Posted September 13, 2008 Thanks it's working now. Nick Quote Link to comment https://forums.phpfreaks.com/topic/124073-solved-cannot-redeclare-mysql_fetch_array/#findComment-640614 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.