• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
have problem to re-write this code to ci script

#1
[eluser]Unknown[/eluser]
hello everyone, have troubles re-write this script in php to codeigniter syntax
Quote:<?php
include("config.inc.php");

if(@mysql_connect($omv_host, $omv_user, $omv_pass)){
mysql_select_db($omv_dbase);
} else {
echo "Sorry a Problem detected";
exit();
}
$omv_sel = mysql_query("SELECT * FROM rotation");
echo "<table class=\"admin_table\" border=\"2\" bordercolor=\"#666666\" width=\"100%\">";
echo "<tr id=\"imp_1\"><td>ID</td><td>Image</td><td>Clicks</td><td>Prints</td></tr>";
while($omv_show = mysql_fetch_assoc($omv_sel)) {
echo "<tr>"."<td id=\"imp_2\" width=\"50\">".$omv_show['ban_id']."</td>"."<td><img src='".$omv_show['></td>"."<td width=\"70\">".$omv_show['ban_click']."</td>"."<td width=\"95\">".$omv_show['ban_print']."</td>"."</tr>";
}
echo "</table>";
?&gt;

someone could aim as I have reviewed the guide but can not make it run
Quote:

#2
[eluser]pistolPete[/eluser]
Read that: http://ellislab.com/codeigniter/user-gui...index.html

Watch the tutorials: http://codeigniter.com/tutorials/

#3
[eluser]Unknown[/eluser]
[quote author="ConwaidD" date="1249729432"]hello everyone, have troubles re-write this script in php to codeigniter syntax
Quote:&lt;?php
include("config.inc.php");

if(@mysql_connect($omv_host, $omv_user, $omv_pass)){
mysql_select_db($omv_dbase);
} else {
echo "Sorry a Problem detected";
exit();
}
$omv_sel = mysql_query("SELECT * FROM rotation");
echo "<table class=\"admin_table\" border=\"2\" bordercolor=\"#666666\" width=\"100%\">";
echo "<tr id=\"imp_1\"><td>ID</td><td>Image</td><td>Clicks</td><td>Prints</td></tr>";
while($omv_show = mysql_fetch_assoc($omv_sel)) {
echo "<tr>"."<td id=\"imp_2\" width=\"50\">".$omv_show['ban_id']."</td>"."<td><img src='".$omv_show['></td>"."<td width=\"70\">".$omv_show['ban_click']."</td>"."<td width=\"95\">".$omv_show['ban_print']."</td>"."</tr>";
}
echo "</table>";
?&gt;

someone could aim as I have reviewed the guide but can not make it run
Quote:
[/quote] i say i reviewed the guide but the guide dosen't have the function mysql_fetch_assoc in the librearies...

#4
[eluser]coolgeek[/eluser]
This function retrieves an array of states that I subsequently format as HTML select options to populate a dropdown via AJAX.

Code:
function getAllStateByCountryId($country_id){
    $data = array();
    $sql = "select id, state from state where country_id = ? order by state";
    $Q = $this->db->query($sql, $country_id);
    if ($Q->num_rows() > 0){
        foreach ($Q->result_array() as $row){
            $data[] = $row;
        }
    }
    $Q->free_result();
    return $data;
}

#5
[eluser]Johan André[/eluser]
[quote author="ConwaidD" date="1249732464"][quote author="ConwaidD" date="1249729432"]hello everyone, have troubles re-write this script in php to codeigniter syntax
Quote:&lt;?php
include("config.inc.php");

if(@mysql_connect($omv_host, $omv_user, $omv_pass)){
mysql_select_db($omv_dbase);
} else {
echo "Sorry a Problem detected";
exit();
}
$omv_sel = mysql_query("SELECT * FROM rotation");
echo "<table class=\"admin_table\" border=\"2\" bordercolor=\"#666666\" width=\"100%\">";
echo "<tr id=\"imp_1\"><td>ID</td><td>Image</td><td>Clicks</td><td>Prints</td></tr>";
while($omv_show = mysql_fetch_assoc($omv_sel)) {
echo "<tr>"."<td id=\"imp_2\" width=\"50\">".$omv_show['ban_id']."</td>"."<td><img src='".$omv_show['></td>"."<td width=\"70\">".$omv_show['ban_click']."</td>"."<td width=\"95\">".$omv_show['ban_print']."</td>"."</tr>";
}
echo "</table>";
?&gt;

someone could aim as I have reviewed the guide but can not make it run
Quote:
[/quote] i say i reviewed the guide but the guide dosen't have the function mysql_fetch_assoc in the librearies...[/quote]

Read the section about the database library.
Maybe read up on the MVC designpattern aswell?

It's hard (and not the least funny) to help people who clearly have not read the docs first... Why should other people code for you? You really need to solve some things yourself. If I post the code here you would just copy and paste it. The problem is that you will never learn and be back here. And on it goes...

My tip is to:

a) Read the user guide (ALL of it) several times.

b) Watch screencasts

c) Create some code

d) Read the user guide and try to find out what you are doing wrong

e) Repeat step c and d MULTIPLE times before asking for help.

Good luck!

#6
[eluser]Zorancho[/eluser]
Code:
$query = $this->db->query(“SELECT * FROM rotation”);
echo “<table class=\“admin_table\” border=\“2\” bordercolor=\”#666666\” width=\“100%\”>”;
echo “<tr id=\“imp_1\”><td>ID</td><td>Image</td><td>Clicks</td><td>Prints</td></tr>”;
foreach($q->result_array() as $row)
{
  
echo “<tr>”.”<td id=\“imp_2\” width=\“50\”>”.$row[‘ban_id’].”</td>”.”<td>”.$row[</td>”.”<td
width=\“70\”>”.$row[‘ban_click’].”</td>”.”<td width=\“95\”>”.$row[‘ban_print’].”</td>”.”</tr>”;
}
echo “</table>”;

#7
[eluser]Zorancho[/eluser]
Just a fix: foreach($query->result_array() as $row)

#8
[eluser]Johan André[/eluser]
[quote author="Zorancho" date="1250009993"]
Code:
$query = $this->db->query(“SELECT * FROM rotation”);
echo “<table class=\“admin_table\” border=\“2\” bordercolor=\”#666666\” width=\“100%\”>”;
echo “<tr id=\“imp_1\”><td>ID</td><td>Image</td><td>Clicks</td><td>Prints</td></tr>”;
foreach($q->result_array() as $row)
{
  
echo “<tr>”.”<td id=\“imp_2\” width=\“50\”>”.$row[‘ban_id’].”</td>”.”<td>”.$row[</td>”.”<td
width=\“70\”>”.$row[‘ban_click’].”</td>”.”<td width=\“95\”>”.$row[‘ban_print’].”</td>”.”</tr>”;
}
echo “</table>”;
[/quote]

That is really horrible code.

1. The query should be in a model.

2. The html should be in a view

3. A controller should get the results from the model and load the view with the data attached to it.

One word (or three): MVC - Model View Controller.

#9
[eluser]Zorancho[/eluser]
@Johan
Dude, that wasn't my intention, i am not suppose to write the whole code for him, i just explained him the way he could do it and the way things work, cause i was once beginner with CI and needed help like this.
While you from the other side left two answers with four times more text than me without any practical help. I guess you just like to talk and judge instead being practical and helpful.

#10
[eluser]Johan André[/eluser]
[quote author="Zorancho" date="1250037769"]@Johan
Dude, that wasn't my intention, i am not suppose to write the whole code for him, i just explained him the way he could do it and the way things work, cause i was once beginner with CI and needed help like this.
While you from the other side left two answers with four times more text than me without any practical help. I guess you just like to talk and judge instead being practical and helpful.[/quote]

I think a gave some help.
I mentioned the userguide and the screencasts.

Obviously he did not watch the screencasts, nor did he read the userguide.
All you need is in there with excellent (well most of the time anyway) examples.
I saw no reason to be "practical" and convert the code for him as he clearly did not understand the basics of the framework. If he presented some CI classes would be another thing. I would gladly help him with it.

I did not comment your code with the intention to be hard on you.
Some people actually writes code like that and I just think it's kindof a bad place to start for a new user, even if the code runs with the indended results.

It's better to take the extra time to learn the right way to do things as it will help you in the long run.


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.