Jump to content

radalin

Members
  • Posts

    179
  • Joined

  • Last visited

    Never

Posts posted by radalin

  1. If you write a query like:

     

    $sql = "SELECT a.id, a.name, b.id, b.surname FROM table1 a, table2 b WHERE b.id = a.id";
    $res = mysql_query($sql);
    //Validate the $res
    while ($row = mysql_fetch_array($res)) {
      var_dump($row)
    }
    

     

    It will work. The problem is on writing the right query with right joins.

  2. Ok then here is part of the code:

     

    <?php
    //Some connection queries are coming here...
    $res = mssql_query("EXEC SP_CAUSING_ERROR");
    if (!$res) {
      logSomething();
    }
    
    $res2 = mssql_query("SELECT * FROM foo"); //The res2 is false...
    if (!$res2) {
      //$res2 is false, even the query is valid and should had to return a valid result.
    }
    ?>
    

     

    Connection seem to be fine but once an error occurs on the stored

    procedures, mssql_query never executes the query and always return

    false.

     

    Note that the second sql query is valid. Has no syntax error or something else. It works pretty well if I silence the execution of the stored procedure.

     

    There is a working connection. On a sql server 2005 profiler I see that "Begin Transaction" command and the second query (the stored procedure) reaches to the database but the rest of it. Connection does not seem be to be closed because if I var_dump($con) it shows the sybase something and not false.

  3. Hi,

     

    I'm currently trying to write a script which connects to a mssql database (sql server 2005) and it starts a transaction.

     

    I calls some stored procedures. (as this is an integration project, most of the sql queries are called as stored procedures instead of stand alone sql queries.) If an error occurs on a stored procedure, mssql_query function seems to return false on every sql query I'm sending.

     

    I do not understand why such a thing happens. Is there anyone who had encountered such an issue.

     

    thanks.

  4. The problem is, if I do not define public/private/protected in the interface, it takes the access level of the method as public and in class if I define it as a private function I get an error like this:

     

    Access level to myClass::prvfnc() must be public (as in class myInterface) in C:\htdocs\file.php on line 12

     

    Is it a bug perhaps?

     

     

    Edit: PHP version is 5.2.6

  5. Hi,

     

    I'm trying to create an interface with private methods. But when I try to run the file, I get an error:

     

    Access type for interface method myInterface::prvfnc() must be omitted in c:\htdocs\file.php on line 12

     

    My interface is like this:

     

    interface myInterface {
      private function prvfnc();
    }
    

     

    and my class is like:

     

    class myClass implements myInterface {
      private function prvfnc() {
        echo "private function call";
      }
    }
    

     

    Is private methods are not allowed in PHP interfaces?

     

    Thanks for your time.

  6. you should check jquery, prototype(scriptacoulous) or dojo for this kind of flashing icons and effects.

     

    I guess you have to use double loops something like this may help you:

     

    for ($i = 0 ;$i < count($server_list); $i++) {
      echo '<tr>';
      for ($j = 0 ; $j < 4; $j++) {  //Instead of 4 put max col number for a row.
        if ($server_list[$i+$j+1]) {
          echo '<td>' . $server_list[$i+$j] . '</td>';
        } else { //If the next one does not exists put a col with left of col number
          echo '<td colspan="' . 4 - $j . '"'>;
        }
      }
      echo '</tr>';
    }
    

     

    Something like this might help you I guess.

  7. But still he can't only get the last name of the actors, he just get movies with that actors. As actors are comma separated values, he has to make some string operation on the select statement to get that part. And it will increase complexity.

  8. Perhaps you are not connected to the database, check that a connection is active.

     

    Also there is a problem with your second query:

     

    $query1="INSERT INTO B " . "(Name,InstallationDate, NumberOfMonths) VALUES ('$Name, $InstallationDate, $NumOfMonths')";

     

    It wont work as the way you have wantend. It must be like:

     

    $query1="INSERT INTO B " . "(Name,InstallationDate, NumberOfMonths) VALUES ('$Name', '$InstallationDate', '$NumOfMonths')";

     

    There are additional single quotes. Also you should really think in using escape functions like mysql_real_escape_string.

  9. It's possible that \r (new line for most ms editors) or \n (newline for rest of the world:) might be added with some editors. These are invisible characters, these characters are recognised by the editor and shown.

     

    When you open a .txt file with vi you see strange chars like ^M, this one refers to "\r". This might be the problem. I had encountered this problem too. Use an editor which you trust :)

  10. There are lot of things are coming from cookies and code is confusing. Why it does multiply with 3, I don't get it. But the problem is perhaps in the math signs order

     

    instead of this

     

    $item_description[$order_items[3*$i+1]]

     

    you should use this perhaps.

     

    $item_description[$order_items[3*($i+1)]]

     

    now the items are increasing with the multiples of 3 (first add 1 to $i than multiply with 3). Former was increasing as multiples of 4 (first multiply with $i than add 1)

     

    maybe this helps.

  11. If you want to get Brad Pitt from the sql qeury, explode won't help you as it's done on your php application. You should do that parsing in your query which is really hard.

     

    You should think to create additional tables for actor/movie and director/movie relation in the database as this is a many-to-many relation (one actor can play more than movies, and more than one actors can play in one movie).

     

    You could want to implement such a way, you have to create three tables: movies, cast and actors.

     

    In actors there is: id, fname, lname

    In movies there is: id, name, year, plot

    In cast there is: id, movie_id, actor_id

     

    movie_id is a reference to movies table id field and actor_id is a reference to actors table id field. And you data becomes something like this.

     

    Actors:

    id  fname    lname

    1    Brad      Pitt 

    2    George  Clooney

     

    Movies:

    id  name                    year        plot

    1    Ocean's Thirteen    2006      they are doing again.

    2    Fight Club            1998        fight!

     

    Cast:

    id  movie_id    actor_id

    1    1              1

    2    1              2

    3    2              1

     

     

    When making the query you can use something like this:

     

    SELECT a.lname

    FROM actors a, movies m, cast c

    WHERE c.actor_id = a.id

        AND m.id = c.movie_id

        AND m.id = $_GET['movie']

     

    It will return you the last name list of the actors playing in that movie

  12. I cannot say I have totally understood what you meant. There is an html part, which looks like part of mysql_fetch_array() loop and than something totally different. The code you have set looks like incomplete, there must be a loop or something there.

     

     

  13. If you use like that, your variable is an escaped variable. If you are using something like:

     

    $event1winnerupdate = mysql_real_escape_string($_POST['event1winnerupdate']);
    
    $query1="UPDATE tournamentevents SET
    eventwinner='$event1winnerupdate' WHERE....  ";
    
    create_folder($event1winnerupdate);
    

     

    you are sending an escaped string to create folders. What you should do is something like this:

     

    $event1winnerupdate = $_POST['event1winnerupdate'];
    
    $query1="UPDATE tournamentevents SET eventwinner='" . mysql_real_escape_string($event1winnerupdate) . "' WHERE....  ";
    
    create_folder($event1winnerupdate);
    

     

    So the folder name you have created is not escaped.

  14. You may use PEAR's XML_Unserializer library if you want.

     

    If you want to parse attributes of a node you just set an option to true and it's okay.

     

    
    $unser = new XML_Unserializer(array("parseAttributes" => true));
    
    $status = $unser->unserialize($xmlString);
    
    if (PEAR::isError($stats)) {
       die("Xml Unserialize error");
    }
    
    $resultArray =  $unser->getUnserializedData();
    
    

     

    You can also tell the parser to put the attributes into a predefined array by setting another option. And with getUnserializedData(), you get the mutli-dimensional associative array.

     

    Hope that helps.

  15. Hi,

     

    I'm curious if it's possible to learn which where clause has returned true on the current query.

     

    Something like:

     

    SELECT *

    FROM table1

    WHERE col1 = 'sometext'

    OR col2 = 1

    OR col3 IN ('some','number','here');

     

    I want to know which where clause has returned true in this query. The col1 or col2 or col3. It can be done by querying all where clauses one by one but i do not prefer it.

     

    Well I hope I was able to explain myself.

     

    Thank you for your time.

     

×
×
  • 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.